16,471
社区成员
发帖
与我相关
我的任务
分享
CString strText(_T("\\u5f6d\\u65af\\u9676"));
int nCount = strText.Replace(_T("\\u"), _T(" 0x"));
wchar_t* buf = new wchar_t[nCount+1];
memset(buf, 0, sizeof(wchar_t)*(nCount+1));
int nIndex = 0;
TCHAR seps[] = _T(" ");
TCHAR* token = _tcstok(strText.GetBuffer(strText.GetLength()), seps);
while(NULL != token)
{
buf[nIndex++] = _tcstoul(token, NULL, 16);
token = _tcstok(NULL, seps);
}
strText.ReleaseBuffer();
AfxMessageBox(CString(buf));
delete[] buf;
buf = NULL;
//**************************************
// unicode字符串转ansi字符串
// 返回大于0成功,小于0失败
//**************************************
int
ustr_astr( WCHAR *unicodestr, char *ansistr )
{
int result = 0;
try
{
int needlen = WideCharToMultiByte( CP_ACP, 0, unicodestr, -1, NULL, 0, NULL, NULL );
if( needlen < 0 )
{
return needlen;
}
result = WideCharToMultiByte( CP_ACP, 0, unicodestr, -1, ansistr, needlen + 1, NULL, NULL );
if( result < 0 )
{
return result;
}
return ( result - 1 );
}
catch( ... )
{
ShowError();
}
return result;
}
WCHAR str[4] = {0x5f6d, 0x65af,0x9676};
MessageBox(NULL, str, str, MB_OK);