carriage return and line feed

Regarding the carriage return and line feed between different systems, you can refer to the following URLs. These are some historical problems:

URL 1: https://blog.csdn.net/pk_20140716/article/details/49642039

网址2:https://blog.csdn.net/fanwenbo/article/details/54848429

It is very clear

I summarize here:

In the earliest era of mechanical typewriters, after each line was typed, it was necessary to push the "carriage" to the left starting position and start a new line, which involved two actions, one was carriage return and line feed

Then there was the teletype, which could type 10 characters per second. But it has a problem, that is, it takes 0.2 seconds when the typewriter wraps a line after typing, which is just enough to type two characters. If in this 0.2 seconds, a new character is passed, then this character will be lost. The researchers added two end-of-line characters to each line. One, called "return," told the typewriter to position the printhead at the left edge; the other, called "new line," told the typewriter to move the paper down one line.

Later, when computers were invented, memory was still very expensive. Some people thought that adding two characters at the end of each line was too wasteful. Doesn’t this take up space? Just add one. Thus, a disagreement arose.

In Linux/Unix systems, each line ends with only "<newline>", that is, "\n"; in
Windows/DOS systems, each line ends with "<newline> <carriage return>", that is, "\r\n";

On Mac systems, each line ends with " <carriage return> ". "Mac 9 and earlier versions use the EOL (End Of Line) character as a newline character, and OSX and later use \r to indicate a newline"

system type Characters used for carriage return and line feed
Linux/Unix \n = Newline = 0x0A = 10 = LF =Line Feed = 换行 = Ctrl + J
Mac \r = Return = 0x0D = 13 = CR = Carriage Return = 回车 = Ctrl + M
Windows/Dos \r \n = 0x0D 0x0A = CR LF = carriage return line feed

A direct consequence is that if a file under Unix/Mac system is opened in Windows, all text will become one line; and if a file in Windows is opened under Unix/Linux, there may be an extra ^M at the end of each line symbol. Open under Mac shows "^J"

The carriage return (\r) is to return to the beginning of the current line without moving down a line, which is equivalent to the return
line feed (\n) of the character carriage, which means that the cursor moves down a line but does not move to the beginning of the line, which is equivalent to a volume roll of paper

After the Enter key is pressed, it will execute \r\n, which is the general carriage return we see, so if you look at a text in hexadecimal file viewing mode, you will find "\r\n" at the end of the line

Strictly speaking, ↵ is "return (return)", Enter is "input" (input the command of the buffer into the computer), the "enter key" on the keyboard now mostly marks these two symbols at the same time, It shows that it has both functions at the same time, so everyone does not distinguish it very much.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325849883&siteId=291194637