.NET"默认的行终止"? [英] .NET "default line terminator"?

查看:221
本文介绍了.NET"默认的行终止"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法找出什么.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.

推荐答案

<一个href="http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.appendline.aspx"><$c$c>StringBuilder.AppendLine将使用<一个href="http://msdn.microsoft.com/en-us/library/system.environment.newline.aspx"><$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;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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