Recent

Author Topic: [SOLVED] How does TStringList and TMemo deal with EOL (line break) characters?  (Read 2510 times)

AMJF

  • New Member
  • *
  • Posts: 48
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?
« Last Edit: August 04, 2021, 10:25:40 am by AMJF »

GAN

  • Sr. Member
  • ****
  • Posts: 370
Re: How does TStringList and TMemo deal with EOL (line break) characters?
« Reply #1 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
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

AMJF

  • New Member
  • *
  • Posts: 48
Re: How does TStringList and TMemo deal with EOL (line break) characters?
« Reply #2 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.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How does TStringList and TMemo deal with EOL (line break) characters?
« Reply #3 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>
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

AMJF

  • New Member
  • *
  • Posts: 48
Re: How does TStringList and TMemo deal with EOL (line break) characters?
« Reply #4 on: August 04, 2021, 10:25:23 am »
I see now.

Thanks!  :)

 

TinyPortal © 2005-2018