多字节与宽字节相互转换的方法
2011-04-08 08:41
148 查看
也就是WideCharToMultiByte和MultiByteToWideChar函数的使用方法。
多字节向宽字节转换:
wstring converToWideChar( const string& str )
{
int len = 0;
len = str.length();
int unicodeLen = ::MultiByteToWideChar(CP_UTF8,0,str.c_str(),-1,NULL,0);
wchar_t * pUnicode;
pUnicode = new wchar_t[unicodeLen+1];
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
::MultiByteToWideChar(CP_UTF8,0,str.c_str(),-1,(LPWSTR)pUnicode,unicodeLen);
wstring rt;
rt = ( wchar_t* )pUnicode;
delete pUnicode;
return rt;
}
宽字节向多字节转换:
string converToMultiChar( const wstring& str )
{
char* pElementText;
int iTextLen;
// wide char to multi char
iTextLen = WideCharToMultiByte( CP_ACP,
0,
str.c_str(),
-1,
NULL,
0,
NULL,
NULL );
pElementText = new char[iTextLen + 1];
memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) );
::WideCharToMultiByte( CP_ACP,
0,
str.c_str(),
-1,
pElementText,
iTextLen,
NULL,
NULL );
string strText;
strText = pElementText;
delete[] pElementText;
return strText;
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/primer_programer/archive/2007/12/26/1968141.aspx
多字节向宽字节转换:
wstring converToWideChar( const string& str )
{
int len = 0;
len = str.length();
int unicodeLen = ::MultiByteToWideChar(CP_UTF8,0,str.c_str(),-1,NULL,0);
wchar_t * pUnicode;
pUnicode = new wchar_t[unicodeLen+1];
memset(pUnicode,0,(unicodeLen+1)*sizeof(wchar_t));
::MultiByteToWideChar(CP_UTF8,0,str.c_str(),-1,(LPWSTR)pUnicode,unicodeLen);
wstring rt;
rt = ( wchar_t* )pUnicode;
delete pUnicode;
return rt;
}
宽字节向多字节转换:
string converToMultiChar( const wstring& str )
{
char* pElementText;
int iTextLen;
// wide char to multi char
iTextLen = WideCharToMultiByte( CP_ACP,
0,
str.c_str(),
-1,
NULL,
0,
NULL,
NULL );
pElementText = new char[iTextLen + 1];
memset( ( void* )pElementText, 0, sizeof( char ) * ( iTextLen + 1 ) );
::WideCharToMultiByte( CP_ACP,
0,
str.c_str(),
-1,
pElementText,
iTextLen,
NULL,
NULL );
string strText;
strText = pElementText;
delete[] pElementText;
return strText;
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/primer_programer/archive/2007/12/26/1968141.aspx
相关文章推荐
- 多字节与宽字节相互转换的方法
- 十六进制数与字节数组相互转换方法
- 字节码问题--wchar和char的区别以及wchar和char之间的相互转换字符编码转换等方法及函数介绍
- 在C#中将任意数值类型数据与字节数组相互转换的一个方法
- 字节码问题--wchar和char的区别以及wchar和char之间的相互转换字符编码转换等方法及函数介绍
- 图片与字节数组相互转换的方法
- java中对象与字节数组相互转换
- mfc宽字节widechar与多字节multiChar相互转换
- java 二进制,八进制,十进制,十六进制间相互转换的方法
- java 二进制,八进制,十进制,十六进制间相互转换的方法
- Bitmap和Drawable相互转换方法
- JS实现汉字与Unicode码相互转换的方法详解
- jedis实现redis的消息队列、发布对象消息、字节数组与字符串相互转换
- 用标准C++做的string和wstring相互转换方法,经过大规模测试
- java 二进制,八进制,十进制,十六进制间相互转换的方法
- js jquery js的DOM与Jquery相互转换,js控制select的方法
- php中实现xml与mysql数据相互转换的方法
- Android中 Bitmap和Drawable相互转换的方法
- win32内核程序中进程的pid,handle,eprocess之间相互转换的方法
- Android:Bitmap和Drawable相互转换方法