加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 将字符串的字符编码从windows-1252转换为utf-8

发布时间:2020-12-15 06:43:23 所属栏目:百科 来源:网络整理
导读:我已将Word文档(docx)转换为html,转换的html具有 Windows-1252作为其字符编码.在.Net中,这个1252字符编码,所有的特殊字符都显示为’ ‘.这个html正在Rad编辑器中显示,如果html是Utf-8格式的,它将正确显示. 我尝试了以下代码,但没有静脉 Encoding wind1252 =
我已将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,utf8Bytes.Length)];   
utf8.GetChars(utf8Bytes,utf8Bytes.Length,utf8Chars,0);  
string utf8String = new string(utf8Chars);

关于如何将html转换成UTF-8的任何建议?

解决方法

这应该做到:
Encoding wind1252 = Encoding.GetEncoding(1252);
Encoding utf8 = Encoding.UTF8;  
byte[] wind1252Bytes = wind1252.GetBytes(strHtml);
byte[] utf8Bytes = Encoding.Convert(wind1252,wind1252Bytes);
string utf8String = Encoding.UTF8.GetString(utf8Bytes);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读