public string UTF8toGB2312(string str)
{
string utfStr = str;
byte[] utfBytes = System.Text.Encoding.UTF8.GetBytes(utfStr);
byte[] gbBytes = System.Text.Encoding.Convert(System.Text.Encoding.UTF8,System.Text.Encoding.GetEncoding("gb2312"),utfBytes);
char[] asciiChars = new char[System.Text.Encoding.GetEncoding("gb2312").GetCharCount(gbBytes, 0, gbBytes.Length)];
System.Text.Encoding.GetEncoding("gb2312").GetChars(gbBytes, 0, gbBytes.Length, asciiChars, 0);
string gbStr = new string(asciiChars);
return gbStr;
}
可惜转来转去不成功啊,郁闷了~{
string utfStr = str;
byte[] utfBytes = System.Text.Encoding.UTF8.GetBytes(utfStr);
byte[] gbBytes = System.Text.Encoding.Convert(System.Text.Encoding.UTF8,System.Text.Encoding.GetEncoding("gb2312"),utfBytes);
char[] asciiChars = new char[System.Text.Encoding.GetEncoding("gb2312").GetCharCount(gbBytes, 0, gbBytes.Length)];
System.Text.Encoding.GetEncoding("gb2312").GetChars(gbBytes, 0, gbBytes.Length, asciiChars, 0);
string gbStr = new string(asciiChars);
return gbStr;
}
最后没办法,把新做的这一页单独转成了gb2312的,在load里添加:
if (!IsPostBack)
Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
各位高人帮忙看看上面的那段代码怎么不成功呢?