How can i extract randomstring between A & B. For example:
A randomstring B
Assuming that "randomstring" doesn't contain the enclosing strings "A" or "B", you can use two calls to pos to extract the string:
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;
The function will return an empty string when either A or B are not found.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With