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 删除字符串重复的符号只保留一个

Delphi 时间差函数及部分字符串与日期时间相互转换的函数

Delphi 时间戳与日期互转

Delphi 复杂数据类型

Delphi 调出windows 系统时间设置对话框

Delphi treeview中显示mainmenu菜单

Delphi 创建自己的定时器 定时清理内存

Delphi把一个字符串中的某个子串,用另一个子串去替换

Delphi pagecontrol不显示tab方式

Delphi fdmemtable1 内存表字段排序

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



打赏

取消

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

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

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

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

评论

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