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

相关阅读 >>

Delphi 文件路径结尾去掉“\”

Delphi 打开网页的两种方法

Delphi xe并行编程:ttask

Delphi 不管什么datetime日期格式时间格式转换都不会错了

Delphi中创建json字符串

Delphi 读写文本

Delphi-edit中只能输入数字且只能输入一个小数点

Delphi 双击tmemo选择光标所在行

Delphi10.3通过json.serializers单元对大量数据序列化

Delphi 调用系统图片查看器

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...