GB2312转换成UTF-8与utf_8转换成GB2312
本文转载:http://www.cnblogs.com/jonhson/archive/2010/08/10/1796536.html
/// <summary>
/// utf_8转换成GB2312
/// </summary>
/// <param name="utfInfo"></param>
/// <returns></returns>
private string ToGB2312(string utfInfo)
{
string gb2312Info = string.Empty;
Encoding utf8 = Encoding.UTF8;
Encoding gb2312 = Encoding.GetEncoding("gb2312"); byte[] unicodeBytes = utf8.GetBytes(utfInfo); 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);
string gb2312info = new string(asciiChars);
return gb2312info;
} /// <summary>
/// GB2312转换成UTF-8
/// </summary>
/// <param name="gbInfo"></param>
/// <returns></returns>
private string ToUTF8(string gbInfo)
{
string Info = string.Empty;
Encoding gb2312 = Encoding.GetEncoding("gb2312");
Encoding utf_8 = Encoding.GetEncoding("UTF-8"); byte[] unicodeBytes = gb2312.GetBytes(gbInfo); byte[] asciiBytes = Encoding.Convert(gb2312,utf_8 , unicodeBytes); char[] asciiChars = new char[utf_8.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
utf_8.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
string info = new string(asciiChars);
return info; }
GB2312转换成UTF-8与utf_8转换成GB2312的更多相关文章
- is 和 == 的区别,utf和gbk的转换,join用法
is 和 == 的区别 # is 比较的是内存地址 # == 比较的是值 a = 'alex' b = 'alex' #int,str(小数据池)会被缓存,为了节约内存 print(id(a),id( ...
- php如何遍历多维的stdClass Object 对象,php的转换成数组的函数只能转换外面一丛数组
php如何遍历多维的stdClass Object 对象,php的转换成数组的函数只能转换外面一丛数组 (2012-09-10 19:58:49) 标签: 杂谈 分类: 网页基础知识 php如何遍历多 ...
- 使用sed,awk将love转换成LOVE,将CHINA转换成china
将love转换成LOVE,将CHINA转换成china echo "love CHINA" | sed -e 's/love/LOVE/' -e 's/CHINA/china/' ...
- 转换编码,将Unicode编码转换成可以浏览的utf-8编码
//转换编码,将Unicode编码转换成可以浏览的utf-8编码 public function unicodeDecode($name) { $pattern = '/([\w]+)|(\\\u([ ...
- C#将字符转换成utf8编码 GB321编码转换
public static string get_uft8(string unicodeString) { UTF8Encoding utf8 = new UTF8Encoding(); Byte[] ...
- js中Json字符串如何转成Json对象(4种转换方式)
js中Json字符串如何转成Json对象(4种转换方式) 一.总结 一句话总结:原生方法(就是浏览器默认支持的方法) 浏览器支持的转换方式(Firefox,chrome,opera,safari,ie ...
- 给定一个字符串,把字符串内的字母转换成该字母的下一个字母,a换成b,z换成a,Z换成A,如aBf转换成bCg, 字符串内的其他字符不改变,给定函数,编写函数 void Stringchang(const char*input,char*output)其中input是输入字符串,output是输出字符串
import java.util.Scanner; /*** * 1. 给定一个字符串,把字符串内的字母转换成该字母的下一个字母,a换成b,z换成a,Z换成A,如aBf转换成bCg, 字符串内的其他字 ...
- matlab学习笔记10_6 字符串与数值间的转换以及进制之间的转换
一起来学matlab-matlab学习笔记10 10_6 字符串与数值间的转换以及进制之间的转换 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考书籍 <matlab 程序设计与综合 ...
- piap.excel 微软 时间戳转换mssql sql server文件时间戳转换unix 导入mysql
piap.excel 微软 时间戳转换mssql sql server文件时间戳转换unix 导入mysql 需要不个mssql的sql文件导入mysql.他们的时间戳格式不同..ms用的是自定义的时 ...
随机推荐
- thinksns解析1
1.数据库 这儿是关于数据库的封装,还是挺厉害的,最终select中完成sql语句的封装,最后由query来完成底层api 2.初始化过程 sns也是通过框架完成显示调用,一开始通过i ...
- php中foreach()函数与Array数组经典案例讲解
//php中foreach()函数与Array数组经典案例讲解 function getVal($v) { return $v; //可以加任意检查代码,列入要求$v必须是数字,或过滤非法字符串等.} ...
- Python资源汇集
Python资源汇集 一 实用教程 廖雪峰网站 第一,Python教程:提供了循序渐进,重点是可操作的实用教程. 第二,Web App 项目教程.给出一个用16天完成的Python Web APP项目 ...
- c++的四种强制类型转换
http://hb.qq.com/a/20110722/001452.htm ...... C风格的强制类型转换(Type Cast)很简单,不管什么类型的转换统统是:TYPE b = (TYPE)a ...
- bzoj 2049: [Sdoi2008]Cave 洞穴勘测 动态树
2049: [Sdoi2008]Cave 洞穴勘测 Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 3119 Solved: 1399[Submit] ...
- html5--indexedDB
http://www.cnblogs.com/Johnny_Z/archive/2012/11/04/2753331.html http://database.51cto.com/art/201202 ...
- Install php-mcrypt on CentOS 6
http://stackoverflow.com/questions/17109818/install-php-mcrypt-on-centos-6
- AppDomain
AppDomain http://www.cnblogs.com/xiashengwang/archive/2012/07/17/2594623.html http://www.cnblogs.com ...
- [LeetCode#159] Missing Ranges Strobogrammatic Number
Problem: Given a string, find the length of the longest substring T that contains at most 2 distinct ...
- 【VirtualDOM】
前沿技术解密——VirtualDOM miniflycn/qvd Matt-Esch/virtual-dom Facebook React 和 Web Components(Polymer)对比优势和 ...