There are several ways you can do this.
The simplest version:
var
sl : TStringList;
I : Integer;
begin
sl := TStringList.Create;
sl.LoadFromFile();
// No you have an array of strings in memory one for each line
for I := 0 to SL.Count -1 do
begin
sl.strings[I];
end;
sl.SaveToFile();
end;
You can also use other File IO Commands such as:
To Read a text file:
var
t : TextFile;
begin
AssignFile(t,'FileName.txt');
Reset(T);
while not eof(t);
begin
Readln(T,LineOfText);
end;
CloseFile(T);
end;
The to write out what you want..
var
t : TextFile;
begin
AssignFile(t,'FileName.txt');
Rewrite(T);
Writeln(T,LineOfText);
Writeln(T,LineOfText);
Writeln(T,LineOfText);
CloseFile(T);
end;
It should be noted that in reality both of the above methods are actually just rewriting the entire contents of the file.
The TFileStream
class allows you manipulate the actual bytes of a file. In general you would need to read until you found the expected text. Then read ahead and cache the rest of the file, as you write out the new ending of the file.