What is the difference between these characters?

Possible duplicate:
What is the difference between \ r and \ n?

I really would like to know what the difference is between \n , \r , \t , chr(13) , how they are used in a web application, in which OS, etc.

For example, can you confirm that windows use \n\r for a new line, and linux only uses \n correctly? It would be interesting to know about this.

thanks

+3
source share
3 answers

\ n - Line channel - 0x0A - 10 decimal places - LF

\ r - Carriage Return - 0X0D - 13 decimal places - CR

\ t - tab - 0x09 - 9 decimal-ht (horizontal tab)

For detailed hexadecimal values, decimal values: 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 systems, CP / M, MP / M, DOS (MS-DOS, PC-DOS, etc.), Atari TOS, OS / 2, Microsoft Windows, Symbian OS, Palm OS

LF + CR: Acorn BBC wound 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 implementation: QNX pre-POSIX.

For more information about \ n, \ r \ t see below:

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, you can use the following 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 	 
+5
source

These are escape sequences of characters in many languages ​​(c, C ++, java, javascript, .NET, to name a few). They directly translate to equivalent ASCII values ​​(you sent this as chr(13) , which in one language created a character based on this ASCII value).

Their meanings:

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

All this comes from control characters for printers, in turn, from typewriters.

Returning the carriage leads the typewriter to the beginning of the line.

A line channel leads the typewriter to the next line.

A tab moves the typewriter to the next tab.

To translate a typewriter to the beginning of the next line requires a combination of line feed and carriage return.

The differences between windows and unix are related to different solutions on different platforms on how to present a new line. Unix set off with a carriage return (possibly also to save space), Windows with both. Macs used to translate strings for the same.

+6
source

13 in chr(13) is the ASCII code for carriage return. There are many ASCII diagrams for viewing additional codes for use with chr() .

  • Windows uses the carriage return \ newline ( \r\n ) to indicate a new line.
  • MacOS only uses carriage return ( \r )
  • Linux and Unix usually use only a new line ( \n ).
+1
source

Source: https://habr.com/ru/post/1469395/


All Articles