What's the difference between this characters? [duplicate]

末鹿安然 提交于 2019-11-29 23:09:03

问题


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


回答1:


\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 	 



回答2:


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.




回答3:


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).


来源:https://stackoverflow.com/questions/6009038/whats-the-difference-between-this-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!