UTF8和GB2312的相互转换
来源:互联网 发布:手机淘宝人工客服在哪 编辑:程序博客网 时间:2024/05/21 04:42
char* G2U(const char* gb2312){int len = MultiByteToWideChar(CP_ACP, 0, gb2312, -1, NULL, 0);wchar_t* wstr = new wchar_t[len+1];memset(wstr, 0, len+1);MultiByteToWideChar(CP_ACP, 0, gb2312, -1, wstr, len);len = WideCharToMultiByte(CP_UTF8, 0, wstr, -1, NULL, 0, NULL, NULL);char* str = new char[len+1];memset(str, 0, len+1);WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, len, NULL, NULL);if(wstr) delete[] wstr;return str;}char* U2G(const char* utf8){int len = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, NULL, 0);wchar_t* wstr = new wchar_t[len+1];memset(wstr, 0, len+1);MultiByteToWideChar(CP_UTF8, 0, utf8, -1, wstr, len);len = WideCharToMultiByte(CP_ACP, 0, wstr, -1, NULL, 0, NULL, NULL);char* str = new char[len+1];memset(str, 0, len+1);WideCharToMultiByte(CP_ACP, 0, wstr, -1, str, len, NULL, NULL);if(wstr) delete[] wstr;return str;}
无论是GB2312到UTF-8的转换,还是UTF-8到GB2312的转换,都需要注意的是在使用字符串后,需要删除字符串指针。这是因为以上两个方法返回的是字符串指针,如果没有删除将会内存泄漏,可别说我没提醒你哦
0 0
- UTF8和GB2312的相互转换
- gb2312和utf8相互转换:
- ASP GB2312和UTF8编码相互转换的解决方案
- UTF8、GB2312相互转换
- utf8 和 gb2312 的转换
- Utf8和Gb2312相互转化的封装
- GB2312与UTF8相互转换
- GB2312和 UTF8的互相转换函数
- 字符集GB2312判断及UTF8相互转换
- GB2312和utf8编码转换
- UTF8和GB2312编码转换
- utf-8和gb2312的相互转换
- GB2312和UTF-8的相互转换
- UTF8 到GB2312 的 转换
- c#实现GB2312和UTF8字符编码方式的转换!
- pb字符串实现GB2312与Unicode、UTF8之间的相互转换
- gb2312和UTF8的解码
- Linux下 GB2312和UTF8转换接口
- 【小镇的技术天梯】Scapy学习日记(三)
- Pend Lists
- 机房重构之SqlHelper
- static静态变量分析
- Git版本控制:Gitlab及Coding.net的使用
- UTF8和GB2312的相互转换
- 默认参数和占位参数
- os_core.c
- 浅谈JavaScript的全局变量跟局部变量
- webStorm:正确的代码也提示绿色下划线的解决方法
- Hibernate应用开发学习笔记1
- 【每周一文】Collaborative Filtering for Implicit Feedback Datasets(2008)
- 函数重载
- CGI/FastCGI学习-篇一