delphitstringlist indexof find 查找字符串

it2026-05-07  3

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/archive/2011/09/21/2184104.html

相关资源:TList查询,查找!
最新回复(0)