问题描述
有没有办法找出什么.NET是使用它的默认的行终止符?例如,对于StringBuilder.AppendLine(串)的文件称,将指定的字符串后面是默认的行终止符的副本......。一些文本相关的类.NET是指同一个概念。
Is there any way to figure out what .NET is using as its "default line terminator"? For example, documentation for StringBuilder.AppendLine(String) says it "Appends a copy of the specified string followed by the default line terminator...". Several text-related classes in .NET refer to the same concept.
有没有办法以编程方式找出被用作线路终端(在运行时)?或者是安全的假设,它永远是\ r \ n表示在Windows机器?我宁愿不硬code,它的价值在我的code,如果我能避免它。
Is there any way to programmatically figure out what is being used as the line terminator (at runtime)? Or is it safe to assume that it will always be "\r\n" for a Windows machine? I'd rather not hard-code that value into my code if I can avoid it.
推荐答案
<$c$c>StringBuilder.AppendLine将使用<$c$c>Environment.NewLine,这是 \ r \ñ
对于非Unix平台和 \ñ
的Unix平台。
StringBuilder.AppendLine
will use Environment.NewLine
, which is "\r\n
" for non-Unix platforms and "\n
" for Unix platforms.
这将永远是 \ r \ñ
的Windows计算机上,但您可以使用 Environment.NewLine
,以代替硬codeD值。
It will always be "\r\n
" for a Windows machine, but you can use Environment.NewLine
in lieu of a hard-coded value.
感谢@Guffa验证这个的
这篇关于.NET&QUOT;默认的行终止&QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!