C# GB2312和UTF8间相互转换

public static string Gb2312_To_UniCode(string strGb2312)
{
    System.Text.Encoding E_Gb2312 = System.Text.Encoding.GetEncoding("gb2312");
    System.Text.Encoding E_Utf8 = System.Text.Encoding.UTF8;
    return E_Utf8.GetString(System.Text.Encoding.Convert(E_Gb2312, E_Utf8, E_Gb2312.GetBytes(strGb2312)));
}

public static string UniCode_To_Gb2312(string strUnicode)
{
    System.Text.Encoding E_Gb2312 = System.Text.Encoding.GetEncoding("gb2312");
    System.Text.Encoding E_Utf8 = System.Text.Encoding.UTF8;
    return E_Gb2312.GetString(System.Text.Encoding.Convert(E_Utf8, E_Gb2312, E_Utf8.GetBytes(strUnicode)));
}

你可能感兴趣的:(C# GB2312和UTF8间相互转换)