提取标签之间的字符串(重复标签)
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.
无
《学习大师原创文档,请勿转载,侵权必究》