2013年11月5日 星期二

c# convert utf8 to big5

public string ConvertBig5(string strUtf)
    {
        System.Text.Encoding utf81 = System.Text.Encoding.GetEncoding("utf-8");
        System.Text.Encoding big51 = System.Text.Encoding.GetEncoding("big5");
        Response.ContentEncoding = big51;
        byte[] strUtf81 = utf81.GetBytes(strUtf.Trim());
        byte[] strBig51 = System.Text.Encoding.Convert(utf81, big51, strUtf81);

        char[] big5Chars1 = new char[big51.GetCharCount(strBig51, 0, strBig51.Length)];
        big51.GetChars(strBig51, 0, strBig51.Length, big5Chars1, 0);
        string tempString1 = new string(big5Chars1);
        return tempString1;
    }

沒有留言:

張貼留言