判断字符串是否为ISO编码,如果是则转换
string test = @"å·²å®ç¼´";
// test = "南京不木人力资源有限公司";
if (IsValidISO(test))
{
Encoding iso = Encoding.GetEncoding("ISO-8859-1");
Encoding utf8 = Encoding.UTF8;
byte[] utfBytes = utf8.GetBytes(test);
byte[] isoBytes = Encoding.Convert(utf8, iso, utfBytes);
string msg = utf8.GetString(isoBytes);
}
private static bool IsValidISO(string input)
{
byte[] bytes = Encoding.GetEncoding("ISO-8859-1").GetBytes(input);
String result = Encoding.GetEncoding("ISO-8859-1").GetString(bytes);
return String.Equals(input, result);
}