Delphi 提取标签之间的字符串
2022-12-26 10:51:02 作者:admin
本文整理自网络,侵删。
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 sysutils.lastdelimiter - 判断一个字符串在另一个字符串中最后出现的位置
Delphi 写变速齿轮外挂
Delphi 链接获取主站地址
shellexecute()和winexec()区别
Delphi 10.4 新变化:定制拖管记录(结构)类型
Delphi中获取客户区坐标
Delphi sysutils.lastdelimiter - 判断一个字符串在另一个字符串中最后出现的位置
Delphi 判断当前活动窗口
Delphi的tfilestream
Delphi 得到指定文件夹内文件名
更多相关阅读请进入《Delphi》频道 >>
猜你喜欢
联络方式:
400-123-789
邮箱:xiachao@163.com
Q Q:12345678
微信公众号
微信二维码