UNICODE GBK UTF-8 编码互转(VC++)
来源:互联网 发布:淘宝网购物步骤 编辑:程序博客网 时间:2024/06/11 17:08
1:UNICODE和GBK互转
wstring MBytesToWString(const char *lpcszString){int len = strlen(lpcszString);int unicodeLen = ::MultiByteToWideChar(CP_ACP, 0, lpcszString, - 1, NULL, 0);wchar_t *pUnicode = new wchar_t[unicodeLen + 1];memset(pUnicode, 0, (unicodeLen + 1) *sizeof(wchar_t));::MultiByteToWideChar(CP_ACP, 0, lpcszString, - 1, (LPWSTR)pUnicode, unicodeLen);wstring wString = (wchar_t *)pUnicode;delete [] pUnicode;return wString;}string WStringToMBytes(const wchar_t *lpwcszWString){char *pElementText;int iTextLen;// wide char to multi chariTextLen = ::WideCharToMultiByte(CP_ACP, 0, lpwcszWString, - 1, NULL, 0, NULL, NULL);pElementText = new char[iTextLen + 1];memset((void *)pElementText, 0, (iTextLen + 1) *sizeof(char));::WideCharToMultiByte(CP_ACP, 0, lpwcszWString, 0, pElementText, iTextLen, NULL, NULL);string strReturn(pElementText);delete [] pElementText;return strReturn;}2:GBK和UTF-8互转
string GBKToUTF8(const string &strGBK){string strOutUTF8 = "";WCHAR *str1;int n = MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), - 1, NULL, 0);str1 = new WCHAR[n];MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), - 1, str1, n);n = WideCharToMultiByte(CP_UTF8, 0, str1, - 1, NULL, 0, NULL, NULL);char *str2 = new char[n];WideCharToMultiByte(CP_UTF8, 0, str1, - 1, str2, n, NULL, NULL);strOutUTF8 = str2;delete [] str1;str1 = NULL;delete [] str2;str2 = NULL;return strOutUTF8;}string UTF8ToGBK(const string &strUTF8){int len = MultiByteToWideChar(CP_UTF8, 0, strUTF8.c_str(), - 1, NULL, 0);WCHAR *wszGBK = new WCHAR[len + 1];memset(wszGBK, 0, (len+1)*sizeof(WCHAR));MultiByteToWideChar(CP_UTF8, 0, (LPCSTR)strUTF8.c_str(), - 1, wszGBK, len);len = WideCharToMultiByte(CP_ACP, 0, wszGBK, - 1, NULL, 0, NULL, NULL);char *szGBK = new char[len + 1];memset(szGBK, 0, len + 1);WideCharToMultiByte(CP_ACP, 0, wszGBK, - 1, szGBK, len, NULL, NULL);//strUTF8 = szGBK;string strTemp(szGBK);delete [] szGBK;szGBK = NULL;delete [] wszGBK;wszGBK = NULL;return strTemp;}3:UNICODE和UTF-8互转
wstring UTF8ToWString(const char *lpcszString){int len = strlen(lpcszString);int unicodeLen = ::MultiByteToWideChar(CP_UTF8, 0, lpcszString, - 1, NULL, 0);wchar_t *pUnicode;pUnicode = new wchar_t[unicodeLen + 1];memset((void *)pUnicode, 0, (unicodeLen + 1) *sizeof(wchar_t));::MultiByteToWideChar(CP_UTF8, 0, lpcszString, - 1, (LPWSTR)pUnicode, unicodeLen);wstring wstrReturn(pUnicode);delete [] pUnicode;return wstrReturn;}string WStringToUTF8(const wchar_t *lpwcszWString){char *pElementText;int iTextLen = ::WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)lpwcszWString, - 1, NULL, 0, NULL, NULL);pElementText = new char[iTextLen + 1];memset((void *)pElementText, 0, (iTextLen + 1) *sizeof(char));::WideCharToMultiByte(CP_UTF8, 0, (LPWSTR)lpwcszWString, - 1, pElementText, iTextLen, NULL, NULL);string strReturn(pElementText);delete [] pElementText;return strReturn;}
0 0
- UNICODE GBK UTF-8 编码互转(VC++)
- UNICODE GBK UTF-8 编码互转(VC++)
- ANSI,UNICODE,UTF-8,GB2312,GBK)编码问题(转)
- 编码:utf-8,unicode,gbk....
- GBK、UTF-8、Unicode 编码
- 字符编码详解及由来(UNICODE,UTF-8,GBK)[转]
- 转:字符编码详解及由来(UNICODE,UTF-8,GBK)
- unicode utf-8 gb18030 gb2312 gbk各种编码对比 [转]
- 字符编码详解(ANSI,UNICODE,UTF-8,GB2312,GBK)
- UNICODE GBK UTF-8等文本编码(理解+实践)
- 中文编码问题(Unicode UTF-8 GBK ...)
- UNICODE,GBK,UTF-8等编码相关
- 中文编码问题(Unicode UTF-8 GBK ...) .
- 编码UNICODE,GBK,UTF-8区别
- UNICODE GBK UTF-8等文本编码
- UNICODE, GBK, UTF-8编码的转换
- Unicode ,UTF-8,assic, gbk, latin1编码
- 关于ASCII、GBK、Unicode、UTF-8编码
- YUV Formats
- 【移动开发】数据抓包与防抓包
- 处理other people游戏代码
- 使用Java导出Excel案例详解
- JWPlayer Uncaught Error: Invalid SRT file
- UNICODE GBK UTF-8 编码互转(VC++)
- 解读代码系统-具有定制列表项的用户界面
- 豌豆夹Redis解决方案Codis安装使用
- php将文件夹打包成zip文件
- 使用DOM创建表格的完整流程
- setValuesForKeysWithDictionary崩溃问题
- Linux操作系统安装前备知识
- ScheduledExecutorService的使用
- OGNL表达式循环List<String[]>类型数据的方法