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.

输出:
Hello This is a Test

来源:https://stackoverflow.com/questions/30827180/delphi-extract-string-between-tags-duplicate-tags

相关阅读 >>

关于如何发现Delphi程序的内存泄漏

Delphi中查找指定文件的例程

Delphi 判断uefi与 legacy bios启动模式

Delphi not 与整数

Delphi idhttp post json 上传 php 接收

Delphi 获取打印机纸型的例子

Delphi html document接口获取网页中所有图片

Delphi fmx 绘制非常精确的 时分秒针

Delphi win10下message无法接收的问题

Delphi 对txt文件的操作

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



打赏

取消

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

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

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

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

评论

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