UTF8 GB2312互转

发布时间:2016-12-11 12:15:45 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"UTF8 GB2312互转",主要涉及到UTF8 GB2312互转方面的内容,对于UTF8 GB2312互转感兴趣的同学可以参考一下。

//UTF-8到GB2312的转换 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的转换 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; }

上一篇:JAVA之抽象类与接口的区别
下一篇:db2日期和时间常用汇总

相关文章

关键词: UTF8 GB2312互转

相关评论