Uwe*_*abe 14
假设"randomstring"不包含封闭字符串"A"或"B",您可以使用两次调用pos来提取字符串:
function ExtractBetween(const Value, A, B: string): string;
var
aPos, bPos: Integer;
begin
result := '';
aPos := Pos(A, Value);
if aPos > 0 then begin
aPos := aPos + Length(A);
bPos := PosEx(B, Value, aPos);
if bPos > 0 then begin
result := Copy(Value, aPos, bPos - aPos);
end;
end;
end;
Run Code Online (Sandbox Code Playgroud)
当找不到A或B时,该函数将返回一个空字符串.