Delphi 提取标签之间的字符串(重复标签)

  • 函数类型: 自定义函数

  • 函数说明:

提取标签之间的字符串(重复标签)


  • 代码如下:



 Function sExtractBetweenTagsB(Const s, LastTag, FirstTag: string): string;
var
  pLast,pFirst,pNextFirst : Integer;
begin
  pFirst := Pos(FirstTag,s);
  pLast := Pos(LastTag,s);
  while (pLast > 0) and (pFirst > 0) do begin
    if (pFirst > pLast) then // Find next LastTag
      pLast := PosEx(LastTag,s,pLast+Length(LastTag))
    else
    begin
      pNextFirst := PosEx(FirstTag,s,pFirst+Length(FirstTag));
      if (pNextFirst = 0) or (pNextFirst > pLast) then begin
        Result := Copy(s,pFirst,pLast-pFirst+Length(LastTag));
        Exit;
      end
      else
        pFirst := pNextFirst;
    end;
  end;
  Result := '';
end;

var
  s: String;

begin
  s := 'Delphi App Hello Hello SomeText here Hello Hello Hello This is a Test! Hello';
  WriteLn(sExtractBetweenTagsB(s,'Test','Hello'));
end.



  • 用法示例:

无 



《学习大师原创文档,请勿转载,侵权必究》





联系电话:
020-00000000
联系电话:
020-00000000
联系电话:
020-12345678