【问题标题】:How change file coding from windows-1251 to utf-8如何将文件编码从 windows-1251 更改为 utf-8
【发布时间】:2012-01-24 08:48:24
【问题描述】:

我有一个 xml 文件,我需要转换从中得到的文本:

我刚开始写代码,但我不知道如何实现这一点:

string text = File.ReadAllText(path);             

XDocument documentcode = XDocument.Load(text);

【问题讨论】:

    标签: c# xml utf-8 xml-parsing


    【解决方案1】:

    阅读时必须指定正确的编码:

     string text = File.ReadAllText(path, Encoding.GetEncoding("windows-1251"));
     XDocument documentcode = XDocument.Parse(text);  // not load. 
    

    写作时你可能不需要做任何特别的事情。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-17
      • 2012-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多