欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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;
}