TStringList provides easy to use LoadFromFile and SaveToFile methods that store a list of string from a text file and saves the list of string to a text file. Each line of the text file represents a string in the list.
procedure TForm1.Button2Click(Sender: TObject);
var
tempStringList : TStringList;
fileName : String;
begin
fileName := 'c:\temp\myfile.txt';
tempStringList := TStringList.Create;
try
tempStringList.LoadFromFile(fileName); {Load string from text file}
tempStringList.SaveToFile(ChangeFileExt(fileName, '.bak')); {save the text in a file with different file extension}
finally
tempStringList.Free;
end;
end;
- 3028 reads