c#对一个字符串的解码
c#对字符串“%u9ad8%u8003%u6570%u5b66%u7efc%u5408%u9898%u89e3%u9898%u601d%u8def%u4e0e%u65b9...
c#对字符串“%u9ad8%u8003%u6570%u5b66%u7efc%u5408%u9898%u89e3%u9898%u601d%u8def%u4e0e%u65b9%u6cd5120%u4f8b”解码函数
最好也给一个编码的函数,谢谢! 展开
最好也给一个编码的函数,谢谢! 展开
展开全部
这是UTF-8编码,原文为:高考数学综合题解题思路与方法120例
// UTF-8 转换 GB2312
private static string UTF8ToGB2312 ( string str ) {
try {
Encoding utf8 = Encoding.UTF8;
Encoding gb2312 = Encoding.GetEncoding ( "gb2312" );
byte[] temp = utf8.GetBytes ( str );
byte[] temp1 = Encoding.Convert ( utf8, gb2312, temp );
string result = gb2312.GetString ( temp1 );
return result;
} catch {
return null;
}
}
// GB2312 转换 UTF-8
private string GB2312ToUTF8(string str)
{
try
{
Encoding utf8 = Encoding.UTF8;
Encoding gb2312 = Encoding.GetEncoding("GB2312");
byte[] unicodeBytes = gb2312.GetBytes(str);
byte[] asciiBytes = Encoding.Convert(gb2312, utf8, unicodeBytes);
char[] asciiChars = new char[utf8.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
utf8.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string result = new string(asciiChars);
return result;
}
catch
{
return "";
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询