【发布时间】:2011-12-08 08:53:58
【问题描述】:
我试图将此字符串的编码从 utf-8 转换为乌克兰语“ÐÑайвеÑ-длÑ-пÑинÑеÑа-Pixma-ip-2000-длÑ-Windows -7-64-биє。 每当我将它从 utf8 转换为 ukranian 时,我都会得到一个损坏的字符串......
正确的字符串应该类似于“Драйвер-для-принтера-Pixma-ip-2000-для-Windows-7-64-бит”..
请指教..谢谢
编辑:这是我转换它的方式..
private string EncodeUTF8toOther(string inputString, string to)
{
try
{
// Create two different encodings.
byte[] myBytes = Encoding.Unicode.GetBytes(inputString);
// Perform the conversion from one encoding to the other.
byte[] convertedBytes = Encoding.Convert(Encoding.Unicode, Encoding.GetEncoding(to), myBytes);
return Encoding.GetEncoding("ISO-8859-1").GetString(convertedBytes);
}
catch
{
return inputString;
}
}
乌克兰语字符集是“KOI8-U”
更多信息:我对这个问题有类似的问题: c# HttpWebResponse Header encoding
位置标头给了我这个损坏的字符串。我需要正确编码才能执行重定向..
【问题讨论】:
-
您的字符串从一开始就看起来像“ÐÑайве...”?那么它已经损坏了。
-
帖子更新了..请检查一下。
-
是的,您的字符串似乎已经损坏/如果您尝试进行反向转换,您将得到损坏的刺痛:'System.Text.Encoding.UTF8.GetString(Encoding.GetEncoding("ISO-8859 -1").GetBytes("ÐÑайвеÑ-длÑ-пÑинÑеÑа-Pixma-ip-2000-длÑ-Windows-7-64-биÑ") )' 结果为 '��айве�-дл�-п�ин�е�а-Pixma-ip-2000-дл�-Windows-7-64-би�'
-
我应该怎么做才能解决这个问题?我也注意到了.. 是 httpWebResponse 的问题吗?