一个网站多个语言版本的 问题乱码显示的解决

困扰了一上午终于解决了

public static string GetO(string str)
{
Byte[] bComments = Encoding.UTF8.GetBytes(str);
char[] cComments = Encoding.UTF8.GetChars(bComments);

StringBuilder charBuilder = new StringBuilder();
foreach(char c in cComments)
{
if(c > '\u0800')
{
charBuilder.Append("&#");
charBuilder.Append((int)c);
}
else
{
charBuilder.Append(c);
}
}
return charBuilder.ToString();
}

显示韩文的文件头

<META http-equiv=Content-Type content="text/html; charset=Unicode (UTF-8 with signature) - Codepage 65001>"

///控件中显示

public static string Fan(string str)
{
str = str.Replace("&#",",");
string[] han = str.Split(',');
StringBuilder sb = new StringBuilder();
for(int i=1;i<han.Length;i++)
{
try
{
sb.Append((char)(int.Parse(han[i].Trim())));

}
catch
{
sb.Append(han[i].Trim());
continue;
}

}
return sb.ToString();
}

你可能感兴趣的:(html,C++,c,C#)