簡體   English   中英

如何從 ISO-8859-1 轉換為 UTF-8?

[英]How to convert from ISO-8859-1 to UTF-8?

我需要將 charset = iso-8859-1 中的 html 文件轉換為 UTF-8,您能幫幫我嗎?

這是我的代碼:

 string converHtml = File.ReadAllText(html);
           
            Encoding iso = Encoding.GetEncoding("windows-1252");
            Encoding utf8 = Encoding.UTF8;
            byte[] isoBytes = iso.GetBytes(converHtml);
            byte[] utf8Bytes = Encoding.Convert(utf8, iso, isoBytes);
            string msg = utf8.GetString(utf8Bytes);
         
            msg = HttpUtility.HtmlDecode(msg);

            return msg;

感謝 Klaus Gütter、Alexei Levenkov,它對我有用。 這是我的代碼:

StreamReader sr = new StreamReader(html, Encoding.GetEncoding(28591));

var ags = sr.ReadToEnd();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM