RosettaCodeData/Task/Globally-replace-text-in-several-files/Pascal/globally-replace-text-in-several-files.pascal
Ingy döt Net d066446780 langs a-z
2013-04-10 22:43:41 -07:00

25 lines
560 B
Text

Program StringReplace;
uses
Classes, StrUtils;
const
fileName: array[1..3] of string = ('a.txt', 'b.txt', 'c.txt');
matchText = 'Goodbye London!';
replaceText = 'Hello New York!';
var
AllText: TStringlist;
i, j: integer;
begin
for j := low(fileName) to high(fileName) do
begin
AllText := TStringlist.Create;
AllText.LoadFromFile(fileName[j]);
for i := 0 to AllText.Count-1 do
AllText.Strings[i] := AnsiReplaceStr(AllText.Strings[i], matchText, replaceText);
AllText.SaveToFile(fileName[j]);
AllText.Destroy;
end;
end.