Delphi samples‎ > ‎

Delphi Strings Tools

Get String Between 2 Strings

function GimeStringBetween(Str,aa,bb:string):string;
var
p1,p2,LLa:Integer;
begin

Result:='';

 p1:=pos(aa,Str);
 p2:=pos(bb,Str);

 LLa:=length(aa);

 if (p1>0)and(p2>0)and(p2>p1) then
 begin
 Result:=Copy(Str,p1+LLa,(p2-p1)-LLa);
 end;

end;



Set/Insert String Between 2 Strings

function SetStringBetween(Str,aa,bb,NewData:string):string;
var
p1,p2,LLa:Integer;
ss:string;
begin

Result:='';

 p1:=pos(aa,Str);
 p2:=pos(bb,Str);

 LLa:=length(aa);

 if (p1>0)and(p2>0)and(p2>p1) then
 begin
 ss:=Copy(Str,p1+LLa,(p2-p1)-LLa);
 Result:=StringReplace(Str,aa+ss+bb,aa+NewData+bb,[rfReplaceAll]);
 end
 else
 Result:=Str+aa+NewData+bb;

end;


../delphi71code/home/delphi-strings-tools..