char* UTF8ToGB2312(const char* pStrUTF8)
{
// 先转成宽字符
int nStrLen = MultiByteToWideChar(CP_UTF8, 0, pStrUTF8, -1, NULL, 0);
wchar_t* pWStr = new wchar_t[nStrLen + 1];
memset(pWStr, 0, nStrLen + 1);
MultiByteToWideChar(CP_UTF8, 0, pStrUTF8, -1, pWStr, nStrLen);
// 再转成GB2312
nStrLen = WideCharToMultiByte(CP_ACP, 0, pWStr, -1, NULL, 0, NULL, NULL);
char* pStr = new char[nStrLen + 1];
memset(pStr, 0, nStrLen + 1);
WideCharToMultiByte(CP_ACP, 0, pWStr, -1, pStr, nStrLen, NULL, NULL);
if(pWStr)
{
delete[] pWStr;
}
return pStr;
}
char* GB2312ToUTF8(const char* pStrGB2312)
{
// 先转成宽字符
int nStrLen = MultiByteToWideChar(CP_ACP, 0, pStrGB2312, -1, NULL, 0);
wchar_t* pWStr = new wchar_t[nStrLen + 1];
memset(pWStr, 0, nStrLen + 1);
MultiByteToWideChar(CP_ACP, 0, pStrGB2312, -1, pWStr, nStrLen);
// 再转为UTF8
nStrLen = WideCharToMultiByte(CP_UTF8, 0, pWStr, -1, NULL, 0, NULL, NULL);
char* pStr
GB2312, BIG5, UTF8, Unicode之间的互换
最新推荐文章于 2014-12-31 13:55:02 发布
本文探讨了GB2312、BIG5、UTF8和Unicode编码之间的互换操作。重点指出在进行编码转换时,UTF8和GB2312都以char*形式表示,转换后的cha*指针需要由调用者负责释放。同时,提供了编码理解的相关链接以供深入学习。
摘要由CSDN通过智能技术生成