Lazarus

Programming => General => Topic started by: AMJF on August 04, 2021, 01:17:17 am

Title: [SOLVED] How does TStringList and TMemo deal with EOL (line break) characters?
Post by: AMJF on August 04, 2021, 01:17:17 am
What I mean is line breaks like Line Feed and Carriage Return.

I am dealing with text files that use LF characters only, which is compatible with Unix, and text files that use LF and CR which works with Windows.

What I would like to know is, does TStringList and TMemo use whatever's in use in the file already as line breaks, or does it imposed Windows-style line breaks? Or can I change the line breaks throughout the file with a function?
Title: Re: How does TStringList and TMemo deal with EOL (line break) characters?
Post by: GAN on August 04, 2021, 01:34:38 am
Or can I change the line breaks throughout the file with a function?
Yes, you can using LineBreak property of TString.

https://www.freepascal.org/docs-html/rtl/classes/tstrings.linebreak.html
Title: Re: How does TStringList and TMemo deal with EOL (line break) characters?
Post by: AMJF on August 04, 2021, 09:18:40 am
Or can I change the line breaks throughout the file with a function?
Yes, you can using LineBreak property of TString.

https://www.freepascal.org/docs-html/rtl/classes/tstrings.linebreak.html

I succeeded in saving a stringlist to a file with linebreak set at #10, but I wonder if the usual #13#10 is also supported? The link indicates a single character is used, even if the variable is declared as a string.
Title: Re: How does TStringList and TMemo deal with EOL (line break) characters?
Post by: lucamar on August 04, 2021, 09:52:50 am
I succeeded in saving a stringlist to a file with linebreak set at #10, but I wonder if the usual #13#10 is also supported? The link indicates a single character is used, even if the variable is declared as a string.

No, it is a string so you can set whatever line-break you want. You could even set it to "[a break here]" and that would be used. :D

For example, this code:
Code: Pascal  [Select][+][-]
  1.   with TStringList.Create do begin
  2.     LineBreak := '<br>';
  3.     Add('Line1');
  4.     Add('Line2');
  5.     Add('Line3');
  6.     Add('Line4');
  7.     Add('Line5');
  8.     SaveToFile('LINEBR.txt');
  9.     Free;
  10.   end;
produces this single line in LINEBR.txt:
Code: Text  [Select][+][-]
  1. Line1<br>Line2<br>Line3<br>Line4<br>Line5<br>
Title: Re: How does TStringList and TMemo deal with EOL (line break) characters?
Post by: AMJF on August 04, 2021, 10:25:23 am
I see now.

Thanks!  :)
TinyPortal © 2005-2018