【发布时间】:2011-04-06 14:29:55
【问题描述】:
我已将 Word 文档(docx)转换为 html,转换后的 html 具有 windows-1252 作为其字符编码。在 .Net 中,对于这种 1252 字符编码,所有特殊字符都显示为“�”。此 html 显示在 Rad 编辑器中,如果 html 为 Utf-8 格式,该编辑器将正确显示。
我试过下面的代码,但没有静脉
Encoding wind1252 = Encoding.GetEncoding(1252);
Encoding utf8 = Encoding.UTF8;
byte[] wind1252Bytes = wind1252.GetBytes(strHtml);
byte[] utf8Bytes = Encoding.Convert(wind1252, utf8, wind1252Bytes);
char[] utf8Chars = new char[utf8.GetCharCount(utf8Bytes, 0, utf8Bytes.Length)];
utf8.GetChars(utf8Bytes, 0, utf8Bytes.Length, utf8Chars, 0);
string utf8String = new string(utf8Chars);
关于如何将 html 转换为 UTF-8 的任何建议?
【问题讨论】:
-
根据您拥有的项目类型(例如 .NetCore),您可能还需要先安装 Nuget 包
System.Text.Encoding.CodePages并在类构造函数中使用Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);进行初始化跨度>