What's the difference between this characters?

2019-02-11 00:33发布

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

3条回答
SAY GOODBYE
2楼-- · 2019-02-11 01:08

The 13 in chr(13) is the ASCII code for carriage return. There are numerous ASCII charts to look at for more codes to use with chr().

  • Windows uses a carriage return \ newline (\r\n) to denote a new line.
  • MacOS uses a carriage return only (\r)
  • Linux and Unix generally uses a new line only (\n).
查看更多
不美不萌又怎样
3楼-- · 2019-02-11 01:13

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:

\n == chr(13) == carriage return
\r == chr(10) == line feed
\t == chr (9) == tab

These all come from control characters for printers, in turn coming from typewriters.

A carriage return brings the typewriter to the beginning of the line.

A line feed brings the typewriter to the next line.

A tab moves the typewriter to the next tab stop.

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.

查看更多
倾城 Initia
4楼-- · 2019-02-11 01:14

\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:

\n in html == 
 or 
 linux, Unix and Mac OS X

\r in html == 
 or 
 Mac(classic)

\r\n in html == 
 or 
 Windows

\t in html == 	 or 	 
查看更多
登录 后发表回答