本文整理自网络,侵删。
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 判断uefi与 legacy bios启动模式
Delphi idhttp post json 上传 php 接收
Delphi html document接口获取网页中所有图片
更多相关阅读请进入《Delphi》频道 >>