What is the universal newline for all operating systems? (LF and CR)

Instead of "universal newline" you could write a "universal format" such as JSON, XML, PDF etc depending if your output is destined to be used as data for another program or a report document to be read by humans.


  • For Windows, it is CRLF
  • For UNIX, it is LF
  • For MAC (up through version 9) it was CR
  • For MAC OS X, it is LF

The simple fact is that it is different for all operating systems. There is no "universal" newline. The best you can do is be aware of the differences.


In the system unit there is a global variable DefaultTextLineBreakStyle set based on the OS. It can be tlbsLF or tlbsCRLF. If it is tlbsLF, use #10, if it is tlbsCRLF use #13 #10.

From system:

type
  TTextLineBreakStyle = (tlbsLF, tlbsCRLF);

var   { Text output line break handling.  Default value for all text files }
  DefaultTextLineBreakStyle: TTextLineBreakStyle = 
  {$IFDEF LINUX} tlbsLF {$ENDIF}
  {$IFDEF MSWINDOWS} tlbsCRLF {$ENDIF}
  {$IFDEF MACOS} tlbsLF {$ENDIF};

I just wonder why it's a var and not a const.


There is no universal newline for all operating systems. You have to use linefeed on some, carriage return on others, and both on some others.

Most text editors can handle multiple kinds of line endings - check your documentation. There are also plenty of utilities that can translate line endings for you.