UTF-8和Unicode编码转换
来源:互联网 发布:带土面具淘宝 编辑:程序博客网 时间:2024/04/29 13:07
CString CXXXDlg::UTF8Convert(CString &str, int sourceCodepage, int targetCodepage)
{
int len=str.GetLength();
int unicodeLen=MultiByteToWideChar(sourceCodepage,0,str,-1,NULL,0);
wchar_t * pUnicode;
pUnicode=new wchar_t[unicodeLen+1];
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
MultiByteToWideChar(sourceCodepage,0,str,-1,(LPWSTR)pUnicode,unicodeLen);
BYTE * pTargetData=NULL;
int targetLen=WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,(char *)pTargetData,0,NULL,NULL);
pTargetData=new BYTE[targetLen+1];
memset(pTargetData,0,targetLen+1);
WideCharToMultiByte(targetCodepage,0,(LPWSTR)pUnicode,-1,(char *)pTargetData,targetLen,NULL,NULL);
CString rt;
rt.Format("%s",pTargetData);
delete pUnicode;
delete pTargetData;
return rt;
}
例如:
UTF8转UNICODE
m_strUnicode = UTF8Convert(m_strUTF8,CP_UTF8,CP_ACP);
UNICODE转UTF8
m_strUTF8 = UTF8Convert(m_strUnicode,CP_ACP,CP_UTF8);
- UTF-8和Unicode编码转换
- gb2312 和 unicode (UTF-8)间的编码转换
- PHP实现Unicode和Utf-8编码相互转换
- 字符编码Unicode UTF-8 GBK的不同和转换
- unicode和UTF-8编码
- UTF-8编码和UNICODE
- Unicode和UTF-8编码
- Unicode编码:UTF-8和UTF-16
- utf-8和Unicode转换
- utf-8编码转换成Unicode
- UTF-8到Unicode的编码转换
- ANSI、UNICODE、UTF-8 文件编码转换
- UTF-8到Unicode的编码转换
- UTF-8 与UniCode 编码转换
- UTF-8到Unicode的编码转换
- C++转换unicode utf-8 gb2312编码
- UNICODE, GBK, UTF-8编码的转换
- ASCII编码和UNICODE、utf-8编码
- 1分钟了解 AngularJS 自定义指令
- Android 按钮水波纹效果
- STM32为什么必须先配置时钟
- springboot pom文件
- 贪污排名 解题报告
- UTF-8和Unicode编码转换
- 移动前端开发需要注意的20个要点
- Java中Synchronized的用法
- 仿支付宝首页(更多)添加、删除、拖拽、点击等功能
- HDU 1005 数学题周期
- 简单易懂的OKHttp调用
- [Axure]QQ注册页面低保真原型
- 关系代数运算符
- CSS盒模型