They both mean "new line" but when is one used over the other?
The /r stands for return or carriage return which owes it's history to the typewriter. A carriage return moved your carriage all the way to the right so you were typing at the start of the line. The /n stands for new line, again, from typewriter days you moved down to a new line.
\r and \n are digital representations of the way you would advance to the next line on a typewriter. \r is a carriage return and \n is a newline (also known as a linefeed). On a typewriter, to go to the start of the new line, you would return the carriage to the leftmost position and then feed the paper up a line.
"\n" is the class Unix/linux style for new line. "\r\n" is the default Windows style for line separator. "\r" is classic Mac style for line separator.
\r\n
is a Windows Style
\n
is a POSIX Style
\r
is a old pre-OS X Macs Style, Modern Mac's using POSIX Style.
\r
is a carriage return and \n
is a line feed, in old computers where it not have monitor, have only printer to get out programs result to user, if you want get printing from staring of new line from left, you must get \n
for Line Feed, and \r
for get Carriage return to the most left position, this is from old computers syntax saved to this time on Windows platform.
\n means new line. It means that the cursor must go to the next line.
\r means carriage return. It means that the cursor should go back to the beginning of the line.
Unix programs usually only needs a new line (\n).
Windows programs usually need both.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With