vb.net vbLf、vbCrLf 和 vbCr 常数之间的差异
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27223228/
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
Differences Between vbLf, vbCrLf & vbCr Constants
提问by Lawrance
I used constants like vbLf
, vbCrLf
& vbCr
in a MsgBox; it produces same output in a MsgBox (Text "Hai" appears in a first paragraph and a word "Welcome" appears in a next Paragraph )
我在MsgBox 中使用了像vbLf
, vbCrLf
&这样的常量;它在 MsgBox 中产生相同的输出(文本“Hai”出现在第一段中,“欢迎”出现在下一段中)vbCr
MsgBox("Hai" & vbLf & "Welcome")
MsgBox ("Hai" & vbCrLf & "Welcome")
MsgBox("Hai" & vbCr & "Welcome")
I know vbLf
, vbCrLf
& vbCr
are used for print and display functions.
我知道vbLf
, vbCrLf
&vbCr
用于打印和显示功能。
I want to know the Difference between the vbLf
, vbCrLf
& vbCr
constants.
我想知道vbLf
, vbCrLf
&vbCr
常量之间的区别。
回答by Vivek S.
Constant Value Description
----------------------------------------------------------------
vbCr Chr(13) Carriage return
vbCrLf Chr(13) & Chr(10) Carriage return–linefeed combination
vbLf Chr(10) Line feed
vbCr: - return to line beginning
Represents a carriage-returncharacter for print and display functions.vbCrLf: - similar to pressing Enter
Represents a carriage-returncharacter combined with a linefeed characterfor print and display functions.vbLf: - go to next line
Represents a linefeed characterfor print and display functions.
vbCr: -返回到行首
代表打印和显示功能的回车符。vbCrLf: -类似于按 Enter
表示回车符与换行符组合,用于打印和显示功能。vbLf: -转到下一行
表示用于打印和显示功能的换行符。
Read More from Constants Class
从常量类中阅读更多内容
回答by AAT
The three constants have similar functions nowadays, but different historical origins, and very occasionally you may be required to use one or the other.
这三个常量如今具有相似的功能,但历史渊源不同,有时您可能需要使用其中一个。
You need to think back to the days of old manual typewriters to get the origins of this. There are two distinct actions needed to start a new line of text:
您需要回想一下旧手动打字机的时代才能了解其起源。开始一行新的文本需要两个不同的操作:
- move the typing head back to the left. In practice in a typewriter this is done by moving the roll which carries the paper (the "carriage") all the way back to the right -- the typing head is fixed. This is a carriage return.
- move the paper up by the width of one line. This is a line feed.
- 将打字头移回左侧。在打字机的实践中,这是通过将承载纸张的卷筒(“托架”)一直向右移动来完成的——打字头是固定的。这是一个回车。
- 将纸张向上移动一行的宽度。这是一个换行符。
In computers, these two actions are represented by two different characters - carriage return is CR
, ASCII character 13, vbCr
; line feed is LF
, ASCII character 10, vbLf
. In the old days of teletypes and line printers, the printer needed to be sent these two characters -- traditionally in the sequence CRLF
-- to start a new line, and so the CRLF
combination -- vbCrLf
-- became a traditional line ending sequence, in somecomputing environments.
在计算机中,这两个动作由两个不同的字符表示——回车是CR
,ASCII 字符 13 vbCr
,;换行符是LF
, ASCII 字符 10, vbLf
. 在电传打字机和行式打印机的旧时代,打印机需要发送这两个字符 - 传统上按顺序CRLF
- 开始新行,因此CRLF
组合 - vbCrLf
- 在某些情况下成为传统的行尾序列计算环境。
The problem was, of course, that it made just as much sense to only use one character to mark the line ending, and have the terminal or printer perform both the carriage return and line feed actions automatically. And so before you knew it, we had 3 different valid line endings: LF
alone (used in Unix and Macintoshes), CR
alone (apparently used in older Mac OSes) and the CRLF
combination (used in DOS, and hence in Windows). This in turn led to the complications of DOS / Windows programs having the option of opening files in text mode
, where any CRLF
pair read from the file was converted to a single CR
(and vice versa when writing).
当然,问题是只使用一个字符来标记行尾,并让终端或打印机自动执行回车和换行操作同样有意义。因此,在您知道之前,我们有 3 种不同的有效行结尾:LF
单独(在 Unix 和 Macintosh 中使用)、CR
单独(显然用于较旧的 Mac 操作系统)和CRLF
组合(在 DOS 中使用,因此在 Windows 中使用)。这反过来又导致 DOS/Windows 程序具有打开文件的选项的复杂性text mode
,CRLF
从文件中读取的任何对都被转换为单个CR
(在写入时反之亦然)。
So - to cut a (much too) long story short - there are historical reasons for the existence of the three separate line separators, which are now often irrelevant: and perhaps the best course of action in .NET is to use Environment.NewLine
which means someone else has decided for you which to use, and future portability issues should be reduced.
所以 - 长话短说 - 存在三个单独的行分隔符是有历史原因的,这些分隔符现在通常是无关紧要的:也许 .NET 中最好的做法是使用Environment.NewLine
这意味着其他人已经为您决定使用哪个,并且应该减少未来的便携性问题。