C#File.ReadAllLines没有中断换行

我有一个我正在构建的应用程序,需要修改配置文件。

我的问题是我无法逐行读取文件。 我一直把整个文件作为单个字符串进行geeting。

string ConfigTemplate = AEBuildsSPFolderName + "\\Template_BuildReleaseScript.Config"; string[] fileSourceLines = File.ReadAllLines(ConfigTemplate, Encoding.Default); //Returns the entire file contents into the first array element. using (StreamReader reader = new StreamReader(ConfigTemplate)) { string line; while ((line = reader.ReadLine()) != null) //Returns the entire file contents into the first line read. 

我知道我做错了什么?

谢谢,

大卫

我猜测使用的换行符可能不是\r\n

当您将整个文件读入单个字符串时,请尝试调用yourString.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries); 并看看它是否适合你。

此外,由于ReadAllLines()只是读入一个字符串,你可以简单地使用ReadAllText()

您的文件可能使用\n字符(不带\r )作为换行符。