How should I handle this situation?
我将编码设置为 UTF8 但仍然出现错误...
我从 MemoryStream
对象创建该字符串(我将其设置为 WebBrowser.DocumentText
),并像这样结束它:
Byte[] buffer = new Byte[ms.Length];
buffer = ms.ToArray();
return System.Text.Encoding.UTF8.GetString(buffer);
我错过了什么?
最佳答案
您将 XML 字符串作为文件名传递。
你可能想写
File.WriteAllText(saveFileDialog.FileName, wb.DocumentText);
或者,
using(StreamWriter writer = new StreamWriter(saveFileDialog.OpenFile(), false, Encoding.UTF8)) {
write.Write(wb.DocumentText);
}
关于c# - 如何处理 XML 中的非法字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3522300/