VC 实现 汉字 GBK(GB2312) 转化为 UTF8 编码
2008-11-24 22:22
831 查看
void ConvertUtf8ToGBK(CString& strUtf8)
{
int len=MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, NULL,0);
unsigned short * wszGBK = new unsigned short[len+1];
memset(wszGBK, 0, len * 2 + 2);
MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -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;
delete[] szGBK;
delete[] wszGBK;
}
void ConvertGBKToUtf8(CString& strGBK)
{
int len=MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, NULL,0);
unsigned short * wszUtf8 = new unsigned short[len+1];
memset(wszUtf8, 0, len * 2 + 2);
MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, wszUtf8, len);
len = WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, NULL, 0, NULL, NULL);
char *szUtf8=new char[len + 1];
memset(szUtf8, 0, len + 1);
WideCharToMultiByte (CP_UTF8, 0, wszUtf8, -1, szUtf8, len, NULL,NULL);
strGBK = szUtf8;
delete[] szUtf8;
delete[] wszUtf8;
}
{
int len=MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -1, NULL,0);
unsigned short * wszGBK = new unsigned short[len+1];
memset(wszGBK, 0, len * 2 + 2);
MultiByteToWideChar(CP_UTF8, 0, (LPCTSTR)strUtf8, -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;
delete[] szGBK;
delete[] wszGBK;
}
void ConvertGBKToUtf8(CString& strGBK)
{
int len=MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, NULL,0);
unsigned short * wszUtf8 = new unsigned short[len+1];
memset(wszUtf8, 0, len * 2 + 2);
MultiByteToWideChar(CP_ACP, 0, (LPCTSTR)strGBK, -1, wszUtf8, len);
len = WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, NULL, 0, NULL, NULL);
char *szUtf8=new char[len + 1];
memset(szUtf8, 0, len + 1);
WideCharToMultiByte (CP_UTF8, 0, wszUtf8, -1, szUtf8, len, NULL,NULL);
strGBK = szUtf8;
delete[] szUtf8;
delete[] wszUtf8;
}
相关文章推荐
- VC 实现 汉字 GBK(GB2312) 转化为 UTF8 编码
- VC 实现 汉字 GBK(GB2312) 转化为 UTF8 编码
- 查询任意汉字的Unicode编码,UTF8编码,GB2312编码,GBK编码
- 【转载】实现UTF8与GB2312编码格式相互转换(VC)已经验证!
- python中的汉字编码问题,兼及Qt,兼及各种编码 unicode, utf8,gbk,gb2312,gb18030.....
- 关于网页中编码gb2312,big5,gbk,utf-8识别的最新方法的探讨和c++的实现
- apache上的编码问题 Tags: 编码 , utf8 , gbk , gb2312
- php检测字符串编码(utf-8,gbk,gb2312)是否为utf8编码的方法总结
- ASCII,unicode, utf8 ,big5 ,gb2312,gbk,gb18030各种常用编码区别
- Javascript 实现gb2312和utf8编码的互换
- javascript 实现utf8到gb2312的编码 以及字符的utf-8编码
- java中以utf8和gbk编码的汉字对应的二进制,以及用unicode进行正则匹配
- VC实现 UTF8转换成GB2312
- ASCII,unicode, utf8 ,big5 ,gb2312,gbk,gb18030等几种常用编码区别
- ruby编译sass出现,gbk转换为utf8编码,转化不了的解决办法
- 字符编码的问题ASCII UTF8 GBK GB2312
- php自定义函数实现汉字转换utf8编码的方法
- [转载]Javascript 实现gb2312和utf8编码的互换
- php检测字符串编码(utf-8,gbk,gb2312)是否为utf8编码的方法总结
- GBK与UTF8 编码转化(C++)