VS 2008 Unicode UTF8 互转
来源:互联网 发布:mysql text使用 编辑:程序博客网 时间:2024/04/30 16:36
亲测可用,备份留用。
wstring CCodec::UTF8ToUnicode( const string& str ){int len = 0;len = str.length();int unicodeLen = ::MultiByteToWideChar( CP_UTF8,0,str.c_str(),-1,NULL,0 ); wchar_t * pUnicode; pUnicode = new wchar_t[unicodeLen+1]; memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t)); ::MultiByteToWideChar( CP_UTF8,0,str.c_str(),-1,(LPWSTR)pUnicode,unicodeLen ); wstring rt; rt = ( wchar_t* )pUnicode;delete pUnicode; return rt; }char* CCodec::UnicodeToUtf8(const wchar_t* buf){char* result;int textlen = 0;textlen = WideCharToMultiByte( CP_UTF8, 0, buf, -1, NULL, 0, NULL, NULL );result =(char *)malloc((textlen+1)*sizeof(char));memset(result, 0, sizeof(char) * ( textlen + 1 ) );WideCharToMultiByte( CP_UTF8, 0, buf, -1, result, textlen, NULL, NULL );return result; }//GBK 转 UTF8void CCodec::ConvertGBKToUtf8(CString& strGBK){int len=::MultiByteToWideChar(CP_ACP, 0, (LPCSTR)strGBK.GetString(), -1, NULL,0);unsigned short * wszUtf8 = new unsigned short[len+1];memset(wszUtf8, 0, len * 2 + 2);::MultiByteToWideChar(CP_ACP, 0, (LPCSTR)strGBK.GetString(), -1, (LPWSTR)wszUtf8, len);len = ::WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)wszUtf8, -1, NULL, 0, NULL, NULL);char *szUtf8=new char[len + 1];memset(szUtf8, 0, len + 1);::WideCharToMultiByte (CP_UTF8, 0, (LPWSTR)wszUtf8, -1, szUtf8, len, NULL,NULL);strGBK = szUtf8;delete[] szUtf8;delete[] wszUtf8;}
0 0
- VS 2008 Unicode UTF8 互转
- UTF8与Unicode互转
- unicode utf8 互转
- GBK UTF8 ANSI UNICODE 互转
- c++ ANSI、UNICODE、UTF8互转
- c++ ANSI、UNICODE、UTF8互转
- c++ ANSI、UNICODE、UTF8互转
- c++ ANSI、UNICODE、UTF8互转
- unicode&utf8
- UTF8/Unicode
- 学习笔记:Unicode与UTF8互转
- 纯C实现unicode-utf8互转
- 纯C实现unicode-utf8互转
- 纯C实现unicode-utf8互转
- win32的ANSI、UNICODE、UTF8互转
- 转码utf8 - unicode 和 unicode - utf8
- 如何处理emoji等4字节的Unicode字符 - utf8mb4 vs. utf8 Collations
- Unicode, ANSI, UTF8
- hdu 5099 Comparison of Android versions(水题)
- poj1611 并查集
- 后缀数组
- RedHat 7.0 安装过程实录
- Hibernate基础映射
- VS 2008 Unicode UTF8 互转
- U盘装linux系统,刻录系统光盘
- PHP模板引擎Smarty(一)Smarty下载、配置、一个最简单的应用示例
- HDU's ACM 1009 FatMouse' Trade
- 单片机精解
- UVA - 11078 Open Credit System
- MS-Gvim的安装和配置
- 易语言操作短信猫
- best coder #17 1002 Select