由於我使用非拉丁字母,如果使用StreamWriter,字符不正確。c#編輯txt文件而不創建另一個文件(沒有StreamWriter)
String line;
StreamReader sr = new StreamReader(@"C:\Users\John\Desktop\result.html");
line = sr.ReadLine();
while (line != null)
{
line = sr.ReadLine();
if (line.Contains("</head>"))
{
line = "<img src=\"result_files\\image003.png\"/>" + line;
}
}
sr.Close();
在這裏我正在編輯我想在文件中編輯的字符串,但我並沒有將它保存在同一個文件中。怎麼做?
請看看這個鏈接http://www.codeproject.com/KB/cs/InsertTextInCSharp.aspx –
我認爲在您的代碼段,你只是操縱堆中的字符串,StreamReader僅用於讀取而不用於寫入,您正在嘗試寫哪個非拉丁字母?它是> signs? – Delashmate
你可以在StreamWriter上設置編碼 –