C# 編碼轉換 UTF8轉GB2312 GB2312轉UTF8

來源:互聯網
上載者:User

標籤:blog   http   ar   sp   on   div   log   bs   html   

來源:http://www.cnblogs.com/mahatmasmile/p/3467495.html
/// <summary> /// GB2312轉換成UTF8 /// </summary> /// <param name="text"></param> /// <returns></returns> public static string gb2312_utf8(string text) { //聲明字元集 System.Text.Encoding utf8, gb2312; //gb2312 gb2312 = System.Text.Encoding.GetEncoding("gb2312"); //utf8 utf8 = System.Text.Encoding.GetEncoding("utf-8"); byte[] gb; gb = gb2312.GetBytes(text); gb = System.Text.Encoding.Convert(gb2312, utf8, gb); //返迴轉換後的字元 return utf8.GetString(gb); } /// <summary> /// UTF8轉換成GB2312 /// </summary> /// <param name="text"></param> /// <returns></returns> public static string utf8_gb2312(string text) { //聲明字元集 System.Text.Encoding utf8, gb2312; //utf8 utf8 = System.Text.Encoding.GetEncoding("utf-8"); //gb2312 gb2312 = System.Text.Encoding.GetEncoding("gb2312"); byte[] utf; utf = utf8.GetBytes(text); utf = System.Text.Encoding.Convert(utf8, gb2312, utf); //返迴轉換後的字元 return gb2312.GetString(utf); }

 

C# 編碼轉換 UTF8轉GB2312 GB2312轉UTF8

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.