The actual character(s) used for new-line are different from one platform to the next. Some systems use character 13
to mean a new-line, some use 10
, and some, like Windows, use both.
Technically, character 13
is supposed to mean a carriage return (return the print head of the printer to the left side of the page), that's why it's often referred to as CR
. Remember, in the early days of computing, printers were used as terminals rather than video screens. So, the closest equivalent of CR
on a video terminal is for the cursor to return to the beginning of the current line, but not advance to the next line.
Character 10
means line-feed (LF
), which means to advance (i.e. feed) the paper by one line so that the print head is ready to print on the next line. The closest equivalent to a line-feed on a video terminal is to move the cursor down to the next line, but keep it at the same x-position.
So, with those two-things in mind, if you wanted to begin typing at the beginning of the next line, you would need to do both things. You need to advance to the next line on the page AND return to the beginning of the line, hence CRLF
, two characters.
Presumably, some system designers thought it was too wasteful to use two characters for each new-line, when the added nuance was rarely needed for computers with video displays, so they opted to only use either CR
or LF
. Since the correct encoding to use changes from one platform to another, it's best to use Environment.NewLine
in .NET to get whichever is appropriate for the current system.
Consider, for example, when you run this console app on windows:
Public Sub Main()
Console.Write("123" & vbCr)
Console.Write("4" & vbCr)
End Sub
The output is:
423
The carriage-return only caused the cursor to go back to the beginning of the line. It didn't cause it to move down to the next line, so the 4, when it's printed, overwrites the 1.