Possible Duplicate:
What is the difference between \r and \n?
I really would like to know what's the difference between \n
, \r
, \t
, chr(13)
, how they are used in a web application, in which OS, and so on.
For example, can you confirm that windows uses \n\r
for the newline, while of linux uses just \n
right? It would be interesting to know these things.
Thanks
The
13
inchr(13)
is the ASCII code for carriage return. There are numerous ASCII charts to look at for more codes to use withchr()
.\r\n
) to denote a new line.\r
)\n
).These are character escape sequences in many languages (c, c++, java, javascript, .NET to name a few). They directly translate to the equivalent ASCII values (you posted this as
chr(13)
which in one language would produce a character based on that ASCII value).Their meanings are:
These all come from control characters for printers, in turn coming from typewriters.
A combination of line feed and carriage return is needed to bring the typewriter to the start of the next line.
The differences between windows and unix stem from the different decisions on the different platforms on how to represent a new line. Unix went with carriage return (probably also to save space), Windows with both. Macs used to use linefeeds for the same.
\n - Line Feed - 0x0A - 10 decimal - LF
\r - Carriage Return - 0X0D - 13 decimal - CR
\t - tab - 0x09 - 9 decimal - ht (horizontal tab)
For detailed hex, decimal values refer: http://web.cs.mun.ca/~michael/c/ascii-table.html
CR+LF: DEC TOPS-10, RT-11 and most other early non-Unix and non-IBM OSes, CP/M, MP/M, DOS (MS-DOS, PC-DOS, etc.), Atari TOS, OS/2, Microsoft Windows, Symbian OS, Palm OS
LF+CR: Acorn BBC spooled text output.
CR: Commodore 8-bit machines, Acorn BBC, TRS-80, Apple II family, Mac OS up to version 9 and OS-9
LF: Multics, Unix and Unix-like systems (GNU/Linux, AIX, Xenix, Mac OS X, FreeBSD, etc.), BeOS, Amiga, RISC OS, and others. However, in tty 'raw mode', CR+LF is used for output and CR is used for input.
RS: QNX pre-POSIX implementation.
For more details on \n, \r \t refer:
http://en.wikipedia.org/wiki/Newline
http://en.wikipedia.org/wiki/Carriage_return
http://en.wikipedia.org/wiki/Horizontal_tab
To use \n \r \t in html for you can use the below codes: