『Delphi』字符串操作——返回子串出现的位置

在项目中,经常涉及对字符串的操作,我将逐渐根据个人体会积累与此。
1 返回子串出现的第一个位置
   Pos(const subStr, s:string;):integer;
   是Delphi自带函数在SysUtils单元
2 返回子串出现的最后一个位置:
  LastPos(const subStr, s:string):integer;
  var
    iPos:Integer;
    strTmp:Widestring;
  begin
    Result:=0;
    strTmp:=s;
    iPos:=Pos(SubStr,strTmp);
    while iPos<>0 do
    begin
      //删除已经查找过的字符
      Delete(strTmp,1,iPos+Length(SubStr)-1);
      Result:=Result+iPos;
      iPos:=Pos(SubStr,strTmp);
      if iPos=0 then Break;
      Result:=Result+Length(SubStr)-1;
    end;
  end;
原文地址:https://www.cnblogs.com/anytao/p/489327.html