string “换行”和“回车”有什么区别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12747722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is the difference between a "line feed" and a "carriage return"?
提问by pheromix
If there are these two keywords then they must have their own meaning. So I want to know what makes them different and what is their code?
如果有这两个关键字,那么它们必须有自己的含义。所以我想知道是什么让他们与众不同,他们的代码是什么?
回答by Tsunamis
A line feedmeans moving one line forward. The code is \n
.
A carriage returnmeans moving the cursor to the beginning of the line. The code is \r
.
甲线馈送装置移动一个线前进。代码是\n
。
甲回车装置将光标移动到该行的开头。代码是\r
。
Windows editors often still use the combination of both as \r\n
in text files. Unix uses mostly only the \n
.
Windows 编辑器通常仍然像\r\n
在文本文件中一样使用两者的组合。Unix 主要只使用\n
.
The separation comes from typewriter times, when you turned the wheel to move the paper to change the line and moved the carriage to restart typing on the beginning of a line. This was two steps.
分离来自打字机时代,当您转动轮子移动纸张以更改行并移动托架以在行首重新开始打字时。这是两个步骤。
回答by Monalisa Das
Since I can not comment because of not having enough reward points I have to answer to correct answer given by @Burhan Khalid.
In very layman language Enter key press is combination of carriage return and line feed.
Carriage return points the cursor to the beginning of the line horizontly and Line feed shifts the cursor to the next line vertically.Combination of both gives you new line(\n) effect.
Reference - https://en.wikipedia.org/wiki/Carriage_return#Computers
由于没有足够的奖励积分而无法发表评论,因此我必须回答@Burhan Khalid 给出的正确答案。
在非常外行的语言中,Enter 键是回车和换行的组合。
回车将光标水平指向行的开头,换行将光标垂直移动到下一行。两者的组合为您提供换行(\n)效果。
参考 - https://en.wikipedia.org/wiki/Carriage_return#Computers
回答by Burhan Khalid
Both of these are primary from the old printing days.
这两者都是旧印刷时代的主要内容。
Carriage return is from the days of the teletype printers/old typewriters, where literally the carriage would return to the next line, and push the paper up. This is what we now call \r
.
回车是从电传打印机/旧打字机的时代开始的,从字面上看,马车会返回到下一行,并将纸张向上推。这就是我们现在所说的\r
。
Line feed LF
signals the end of the line, it signals that the line has ended - but doesn't move the cursor to the next line. In other words, it doesn't "return" the cursor/printer head to the next line.
换LF
行表示该行结束,表示该行已结束 -但不会将光标移动到下一行。换句话说,它不会将光标/打印机头“返回”到下一行。
For more sundry details, the mighty wikipediato the rescue.
有关更多杂项详细信息,请参阅强大的维基百科。