Title: The SearchAndReplace functions
Question:
Answer:
A univeral function of how to replace strings in TStringsList:
procedure SearchAndReplace(aStrList: TStrings; aSearchStr, aNewStr: string);
var i : integer;
s1 : string;
p1 : integer;
begin
for i := 0 to aStrList.Count -1 do
begin
s1 := aStrList[i];
Repeat
p1 := pos(aSearchStr, s1);
if p1 0 then begin
Delete(s1, p1, Length(aSearchStr));
Insert(aNewStr, s1, p1);
aStrList[i] := s1;
end;
until p1 = 0;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SearchAndReplace(Memo1.Lines,Edit1.Text,Edit2.Text);
end;