I have a file .\input.txt
like this:
aaa
bbb
ccc
If I read it using TStrings.LoadFromFile
and write it back (even without applying any changes) using TStrings.SaveToFile
, it creates an empty line at the end of the output file.
var
Lines : TStrings;
begin
Lines := TStringList.Create;
try
Lines.LoadFromFile('.\input.txt');
//...
Lines.SaveToFile('.\output.txt');
finally
Lines.Free;
end;
end;
The same behavior can be observed using the TStrings.Text
property which will return a string containing an empty line at its end.
For Delphi 10.1 and newer there is a property TrailingLineBreak
controlling this behavior.
When TrailingLineBreak property is True (default value) then Text property will contain line break after last line. When it is False, then Text value will not contain line break after last line. This also may be controlled by soTrailingLineBreak option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With