asp.net下UTF-7转GB2312编码的代码(中文)
程序员文章站
2024-03-08 13:45:40
复制代码 代码如下: /// utf-7转换gb2312编码的方法 /// /// &l...
复制代码 代码如下:
/// utf-7转换gb2312编码的方法
/// </summary>
/// <param name="str7"></param>
/// <returns></returns>
public static string utf72unicode(string str7)
{
string sutf7 = "";
if (str7.startswith("&"))
{
sutf7 = "+" + str7.substring(1);
}
else
{
sutf7 = str7;
}
byte[] bytes = system.text.encoding.getencoding("gb2312").getbytes(sutf7);
byte[] byteret = system.text.encoding.convert(system.text.encoding.utf7, system.text.encoding.unicode, bytes);
string sret = system.text.encoding.unicode.getstring(byteret);
return sret;
}