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 stringgrid 实例3: 本例功能: 1、修改 tstringgrid的默认宽与高; 2、添加行; 3、确认当前单元并赋值.

Delphi版ip地址与整型互转

Delphi10.3通过rest单元使类和json数据互相转换

Delphi idhttp returning http 1.1/500 显示错误内容

Delphi 执行程序并等待完成2

Delphi 通过wmi获取u盘硬件特征码

Delphi版的隐藏模块单元 hidemoduleunit.pas

indy10下的tidhttp控件获取源码乱码的解决方法

Delphi调用winapi: getsystemmetrics - 获取系统度量等数值信息

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



打赏

取消

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

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

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

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

评论

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