Python's file objects can now support end of line conventions other than the one followed by the platform on which Python is running. Opening a file with the mode 'U' or 'rU' will open a file for reading in universal newline mode. All three line ending conventions will be translated to a "\n" in the strings returned by the various file methods such as read() and readline().
在 Python 3 中,通用换行符是打开文本文件的默认模式。这意味着,当打开文本文件时,我根本不必关心行结束约定。
我们在 C# 中是否也有这样的便捷功能?
最佳答案
A line is defined as a sequence of characters followed by a line feed ("\n"), a carriage return ("\r"), or a carriage return immediately followed by a line feed ("\r\n"). The string that is returned does not contain the terminating carriage return or line feed.
从文件中读取行的便利方法,例如 File.ReadLines
和 File.ReadAllLines
,使用 StreamReader
引擎盖。
我不知道有什么方法可以将文件中的多行作为字符串读取,但是会默默地用规范化的 \n
替换所有行结束字符。 StreamReader.ReadToEnd()
不会以这种方式处理它读取的文本。
关于c# - C#有没有类似于Python的通用换行符的东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55664784/