End of line characters

Newline/line ending/end of line(EOL), line feed or line break is a control char or sequence of control chars in a char encoding specification used to specify the end of line of text and start of new one. IDEs/text editors put insert this at the end of a line when ‘Enter’/⏎ key is pressed. Unfortunately for us different Operating Systems do this differently for historical reasons.

CR – Macintosh pre OS X

The Carriage Return (CR) character (0x0D, \r) moves the cursor to the beginning of the line without advancing to the next line. This character is used as a new line character in Commodore and Early Macintosh operating systems (OS-9 and earlier).

  • CR
  • \r
  • ASCII code 13

LF – Unix/OS X

The Line Feed (LF) character (0x0A, \n) moves the cursor down to the next line without returning to the beginning of the line. This character is used as a new line character in UNIX based systems (Linux, Mac OSX, etc.)

  • LF
  • \n
  • ASCII code 10

CR and LF – Windows

The End of Line (EOL) sequence (0x0D 0x0A, \r\n) is actually two ASCII characters, a combination of the CR and LF characters. It moves the cursor both down to the next line and to the beginning of that line. This character is used as a new line character in most other non-Unix operating systems including Microsoft Windows, Symbian OS and others.

  • CRLF
  • \r\n
  • ASCII code 13 and then ASCII code 10

Sources / recommended reading:

da block
Zeen's Automatic Middle Of Content Ad Feature

https://blog.codinghorror.com/the-great-newline-schism/

https://blog.codinghorror.com/whitespace-the-silent-killer/

More Stories
Understanding Intel Sandy Bridge and Ivy Bridge processors and Motherboard chipsets.