标签:
JAVA使用UTF-8格式字符串,JAVA与C++通信时将UTF-8串转为UNICODE串,如“ABCDabcd中国人民下沙123.杭州”转为UNICODE后外观如下:
\u41\u42\u43\u44\u61\u62\u63\u64\u4e2d\u56fd\u4eba\u6c11\u4e0b\u6c99\u31\u32\u33\u2e\u676d\u5dde
VC中如下处理即可转回来
CString CXXClass::UnicodeToString() { CString strUnicode = _T("\\u41\\u42\\u43\\u44\\u61\\u62\\u63\\u64\\u4e2d\\u56fd\\u4eba\\u6c11\\u4e0b\\u6c99\\u31\\u32\\u33\\u2e\\u676d\\u5dde"); INT iStart = 0, iEnd = 0; CString strTmp, strOut; TCHAR c; BOOL bEnd = FALSE; for (INT i = 0; i < strUnicode.GetLength(); ++i) { iEnd = strUnicode.Find(_T(‘\\u‘), iStart); if (iEnd < 0) { iEnd = strUnicode.GetLength(); bEnd = TRUE; } strTmp = strUnicode.Mid(iStart + 1, iEnd - iStart - 1); if (!strTmp.IsEmpty()) { swscanf_s(strTmp.GetBuffer(), _T("%x"), &c); strTmp.ReleaseBuffer(); strOut += c; } iStart = iEnd + 1; if (bEnd) { break; } } return strOut; }
应该还有更好的方法,欢迎交流。
VC中含中英文的\u格式UNICODE字符串转UNICODE可见字符串
标签:
原文地址:http://www.cnblogs.com/emacs/p/5424273.html