什么意思是c#" \r"中的回车 [英] what means Carriage return in c# "\r"

查看:91
本文介绍了什么意思是c#" \r"中的回车的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们。我想知道什么是\ r(回车)以及如何使用

hi friends. i want to know what does mean "\r"("Carriage return") and how to works it

推荐答案

由于历史原因,使用了两个旧字符表示文本文件的行(或段落,取决于解释)之间的边界。一个是回车,\ r,另一个是换行,\ n(也是:新行)。您可以在ASCII表中找到它们: ASCII - 维基百科,免费的百科全书 [ ^ ]。



这是好笑,但这些人物模仿机械打字机的行为。这些字母击中了压在橡胶条上的纸张;带有纸张的条安装在托架(它带有它)中,水平移动以从一个字符位置移动到下一个字符位置。线完成后,它一直向左移动。它对应于\ r,回车。然后条形旋转一行,它对应于\ n。这两个操作保持独立,因为一些打字技巧需要仅移动托架来键入已经键入的文本,并且单独旋转条形图以在任意行上打印某些内容。因此,这些操作潜入计算机符号,即使没有打印机实际使用过机械打字机的方式。



在Unicode中,有不同的字符用于类似目的,但是\ r和\ n更经常使用。



更糟糕的是,使用这些字符的规则取决于平台。请参阅: Newline - 维基百科,免费的百科全书 [ ^ ]。



在.NET程序中,大多数情况下(事实上) ,它也取决于目的),你需要使用平台相关的对象, System.Environment.NewLine

环境类(系统) [ ^ ]。



但是,如果您将一个文本文件从一个平台复制到另一个平台,则在目标平台上,您可以使用新的行字符进行非本地使用。这些天来,这不是一个大问题。文本文件的作用被简化为无关紧要的文件格式的媒体,例如HTML,ePUB,Open XML等。在所有平台上,现代文本处理软件(包括文本编辑器)旨在检测不匹配并修复它,正常化。



-SA
By historical reasons, there are two old characters used to denote the boundary between lines (or paragraphs, depending in interpretation) for text files. One is "carriage return", "\r", and another one is "line feed", "\n" (also: "new line"). You can find them in the ASCII table: ASCII — Wikipedia, the free encyclopedia[^].

It's funny, but these characters mimic behavior of mechanical typewriter. The letters hits the paper pressed against the rubberized bar; the bar with the paper is mounted in the "carriage" (it "carries" it) which moves horizontally to move from one character position to the next one. When the line is complete, it moves all the way to the left. It corresponds to "\r", "carriage return". Then the bar rotates by one line, and it corresponds to "\n". These two operations are kept independent, because some typing tricks requires moving just the carriage to type over already typed text, and independent rotation of the bar, to print something on an arbitrary line. So these operations sneaked in computer notation, even though no printer actually used them the way the mechanical typewriter did.

In Unicode, there are different characters used for similar purposes, but "\r" and "\n" are used more often.

Worse, the rules for using these characters depend on the platform. Please see: Newline — Wikipedia, the free encyclopedia[^].

In .NET programs, in most cases (in fact, it also depends on purpose), you need to use platform-dependent object instead, System.Environment.NewLine:
Environment Class (System)[^].

Still, if you copy one text file from one platform to another, on a target platform, you can get "non-native" use of new line characters. These days, this is not a big problem. The role of text files is reduced to the media for the file format where it does not matter, such as, say, HTML, ePUB, Open XML, and so on. On all platform, modern text handling software, including text editors, are designed to detect mismatch and fix it, "normalize".

—SA


基本上回车符\ r将光标移动到当前行的开头。换行符\ n导致下一行,可能是下一行的开头;这是Alexei在上面注意到的平台相关部分(在* nix系统上\ n给你一个回车和一个换行符,在windows中它没有)
Basically A carriage return \r moves the cursor to the beginning of the current line. A newline \n causes a drop to the next line and possibly the beginning of the next line; That's the platform dependent part that Alexei notes above (on a *nix system \n gives you both a carriage return and a newline, in windows it doesn't)


这篇关于什么意思是c#" \r"中的回车的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆