C# UTF-8与GB2312编码的相互转化

GB2312转化为UTF-8:
string LanChange(string str)  
    {  
        Encoding utf8;  
        Encoding gb2312;  
        utf8 = Encoding.GetEncoding("UTF-8");  
        gb2312 = Encoding.GetEncoding("GB2312");  
        byte[] gb = gb2312.GetBytes(str);  
        gb = Encoding.Convert(gb2312,utf8,gb);  
        return utf8.GetString(gb);  
    }  
UTF-8转化为GB2312
string ChangeLan(string text)  
    {  
        byte[] bs = Encoding.GetEncoding("UTF-8").GetBytes(text);  
        bs = Encoding.Convert(Encoding.GetEncoding("UTF-8"), Encoding.GetEncoding("GB2312"), bs);  
        return Encoding.GetEncoding("GB2312").GetString(bs);  
    }  

 

你可能感兴趣的