mathes
asked on
find and replace in strings
Hi experts,
I am searching a source code which replaces all occurencies of an "old" substring in a master-string
to a "new" substring. If the "old" substring can't be found in the master-string, the routine must be
quit without run-time error.
Have you suggestions for me how this could be accomplished?
With kind regards
Mathes
I am searching a source code which replaces all occurencies of an "old" substring in a master-string
to a "new" substring. If the "old" substring can't be found in the master-string, the routine must be
quit without run-time error.
Have you suggestions for me how this could be accomplished?
With kind regards
Mathes
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi experts,
thank you for your excellent advice.
thank you for your excellent advice.
other method
in a function
function replace_it(SourceS, OldS, NewS : String) : String;
var
P : Integer;
STmp, STmp2 : String;
begin
STmp2 := '';
STmp := SourceS;
P := pos(OldS,STmp);
while p <> 0 do
begin
STmp2 := STmp2 + copy(STmp,1,p-1)+NewS;
delete(STmp,1,p+Length(Old
P := pos(OldS,STmp);
end;
STmp2 := STmp2 + STmp;
result := STmp2;
end;
to call example:
procedure TForm1.Button1Click(Sender
begin
memo1.text := replace_it(memo1.text,edit
end;
meikl