delphi tstringlist indexof find 查找字符串

Find是折半查找 速度应该是最快了而indexof默认是 for 循环所有item了。 但find使用前必须先排序 sort 否则返回 index错误。

示例如下:

var  lst:TStringList ;
     i:Integer ;
begin

  lst:=TStringList.Create ;

  try

    lst:=TStringList.Create ;
    lst.CaseSensitive :=true;
    lst.Delimiter :=',';
    lst.DelimitedText :=Edit1.Text ;

    ShowMessage(IntToStr(lst.IndexOf(Edit2.Text) ));
    lst.Sort ;
        if lst.Find(Edit2.Text ,i) then
      ShowMessage(IntToStr(i));
  finally

    lst.Free ;
  end;

eidt2 内容 如下字符串  010a,010A,200a,200b,905a

原文地址:https://www.cnblogs.com/chinawcs/p/2184104.html