C# 如何从ISO-8859-1转换为UTF-8?

C# 如何从ISO-8859-1转换为UTF-8?,c#,C#,我需要将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

我需要将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; StreamReader sr = new StreamReader(html, Encoding.GetEncoding(28591)); var ags = sr.ReadToEnd(); 字符串converHtml=File.ReadAllText(html); Encoding iso=Encoding.GetEncoding(“windows-1252”); Encoding utf8=Encoding.utf8; 字节[]等字节=iso.GetBytes(converHtml); 字节[]utf8Bytes=编码.转换(utf8,iso,等字节); 字符串msg=utf8.GetString(utf8Bytes); msg=HttpUtility.HtmlDecode(msg); 返回味精;
谢谢克劳斯·古特,阿列克谢·列文科夫,这对我很有用。 这是我的代码:

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; StreamReader sr = new StreamReader(html, Encoding.GetEncoding(28591)); var ags = sr.ReadToEnd(); StreamReader sr=newstreamreader(html,Encoding.GetEncoding(28591)); var ags=sr.ReadToEnd();
你有什么问题?为什么不在读取文件时提供编码?看到最有可能应该是重复的,但代码是非常混乱,所以可能有其他东西。。。