Delphi 字符串查找函数


本文整理自网络,侵删。

 
function getLocation(substr,s:string):integer;var i,len,x:integer;    tmp:string;begin  Result:=0;  len:=length(substr);  if len=0 then exit;  tmp:=s;  x:=0;  while length(tmp)>0 do  begin    i:=pos(substr,tmp);    if i>0 then    begin      if (i=1) then      begin        if not(tmp[len+1] in['a'..'z','A'..'Z']) then        begin          Result:=1;          exit;        end;      end      else if (not(tmp[i-1] in['a'..'z','A'..'Z']))and(not(tmp[i+len] in['a'..'z','A'..'Z'])) then      begin        Result:=x+i;        exit;      end      else      begin        x:=x+i+len-1;        tmp:=copy(tmp,i+len,length(tmp));      end;    end    else exit;  end;end;procedure TForm1.Button1Click(Sender: TObject);var i:integer;    substr,s:string;begin  substr:='AAA';  s:='(dsfsAAA ghtyAAAghfg AAAgfhgfh AAA)fdgfd';  i:=getLocation(substr,s);  if i>0 then showmessage('在第 '+inttostr(i)+' 个位置找字符 “'+substr+'"。')  else showmessage('字符串中找不到 “'+substr+'"。');end;

相关阅读 >>

Delphi opendialog1 savedialog1 默认路径

Delphi使用indy组件http上传文件

Delphi中判断一个字符的位置在字符串开头或者末尾

Delphi通过ip或机器名获取局域网mac地址

Delphi formatdatetime 显示日期时间

Delphi�⒆执�传入到windows目前窗口cursor所在位置

Delphi idwhois1 简单的用法

Delphi 创建文件夹并打开

Delphi unigi unidbtreegrid展开叠起 unidbgrid自动调节列宽

Delphi实现图像反色实例4种方法

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



打赏

取消

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

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

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

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

评论

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