UnicodeToUTF8, UTF8ToUnicode
项目中用到了读写utf8格式xml文件,所以写了utf8与unicode转换的函数。
//CString 头文件 #include <afx.h>
//CString 与LPCTSTR通用
阅读更多
//CString 头文件 #include <afx.h>
//CString 与LPCTSTR通用
作用类似于ATL的字符串转换宏 CA2T, T2CA,只不过这俩是针对ANSI的。
介绍:http://blog.csdn.net/earbao/article/details/11696929
注意作用域问题:http://blog.csdn.NET/bloodfighter/article/details/5618846
关于utf8 与 utf16介绍:http://www.cnblogs.com/kingcat/archive/2012/10/16/2726334.html
bool UnicodeToUTF8(const CString &csUnicode, CStringA &csUTF8)
{
#ifdef UNICODE
int nLen = WideCharToMultiByte(CP_UTF8, 0, csUnicode, -1, NULL, 0, NULL, NULL); //确定结果字符串长度
char *cUtf8 = new char[nLen+1];
if(nLen != WideCharToMultiByte(CP_UTF8, 0, csUnicode, -1, cUtf8, nLen, NULL, NULL))
return false;
csUTF8 = cUtf8;
delete[] cUtf8;
#else
csUTF8 = csUnicode;
#endif
return true;
}
bool UTF8ToUnicode(const CStringA &csUTF8, CString &csUnicode)
{
#ifdef UNICODE
int nLen = MultiByteToWideChar(CP_UTF8, 0, csUTF8, -1, NULL, 0);
WCHAR *wcUnicode = new WCHAR[nLen+1];
if(nLen != MultiByteToWideChar(CP_UTF8, 0, csUTF8, -1, wcUnicode, nLen))
return false;
csUnicode = wcUnicode;
delete[] wcUnicode;
#else
csUnicode = csUTF8;
#endif
return true;
}
阅读更多
声明:该文观点仅代表作者本人,入门客AI创业平台信息发布平台仅提供信息存储空间服务,如有疑问请联系rumenke@qq.com。
- 上一篇:没有了
- 下一篇:没有了