【发布时间】:2020-10-21 09:37:24
【问题描述】:
我需要将 charset = iso-8859-1 中的 html 文件转换为 UTF-8,您能帮帮我吗?
这是我的代码:
字符串 converHtml = File.ReadAllText(html); 编码 iso = Encoding.GetEncoding("windows-1252"); 编码 utf8 = Encoding.UTF8; byte[] isoBytes = iso.GetBytes(converHtml); byte[] utf8Bytes = Encoding.Convert(utf8, iso, isoBytes); 字符串味精 = utf8.GetString(utf8Bytes); 味精 = HttpUtility.HtmlDecode(味精); 返回味精;【问题讨论】:
-
你有什么问题?
-
为什么在读取文件时不提供编码?见docs.microsoft.com/en-us/dotnet/api/…
-
很可能应该是 stackoverflow.com/questions/12130290/… 的副本,但是代码非常混乱,所以也许还有其他东西......
标签: c#