Showing posts with label Font Encoding. Show all posts
Showing posts with label Font Encoding. Show all posts

Convert UT8 to GB2312 (Chinese Encoding)

            string GBInfo = string.Empty;
            Encoding utf8 = Encoding.UTF8;
            Encoding gb2312 = Encoding.GetEncoding("gb2312");
            byte[] UnicodeBytes = utf8.GetBytes(str);
            byte[] AscIIBytes = Encoding.Convert(utf8, gb2312, UnicodeBytes);
            char[] AscIIChars = new char[gb2312.GetCharCount(AscIIBytes, 0,   
            AscIIBytes.Length)];
            gb2312.GetChars(AscIIBytes, 0, AscIIBytes.Length, AscIIChars, 0);
            return AscIIBytes;

UTF-8 data from mssql to C# UTF-8 by SQLReader

byte[] bytes = Encoding.GetEncoding(1252).GetBytes(m_orderdetail.productDescCN);//((string)reader["Note"]);
m_orderdetail.productDescCN = Encoding.UTF8.GetString(bytes);