我有一個應用程序,我正在建設需要修改配置文件。C#File.ReadAllLines不會打破換行
我的問題是我無法逐行閱讀文件。我將整個文件作爲單個字符串進行保存。
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.
任何想法我做錯了什麼?
感謝,
大衛
感謝您的回覆。 基於您的意見,下面是測試代碼段我放在一起...... //獲取文件行 的String [] fileSourceLines = File.ReadAllLines(ConfigTemplate,Encoding.Default); (fileSourceLines.Length == 1) if(fileSourceLines.Length == 1) string yourString = fileSourceLines [0]; string [] newSourceLines = yourString.Split(new char [] {'\ r','\ n'},StringSplitOptions.RemoveEmptyEntries); //這個數組仍然只包含1個字符串。 } newSourceLines數組仍然只包含1個字符串。 任何其他建議:) 謝謝, 大衛 – 2010-05-06 01:59:45
好吧,我才發現,這是這個問題.....感謝每個人的幫助! – 2010-05-06 02:03:28