码迷,mamicode.com
首页 > Windows程序 > 详细

C# 编码转换 UTF8转GB2312 GB2312转UTF8

时间:2014-11-30 16:38:21      阅读:193      评论:0      收藏:0      [点我收藏+]

标签: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

标签:blog   http   ar   sp   on   div   log   bs   html   

原文地址:http://www.cnblogs.com/TNSSTAR/p/4133227.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!