1. 程式人生 > >將Unicode編碼值轉換為Unicode字串

將Unicode編碼值轉換為Unicode字串

編碼值格式為 \u004c\u004f\u0053\u0054\u002e\u0044\u0049\u0052

wstring TranslateString(LPCWSTR szOrig)

{
wstring wStr;
LPCWSTR curChar = szOrig;


while (*curChar)
{
if (curChar[0] == '\\' &&
(curChar[1] == 'u' || curChar[1] == 'U') &&
IS_NUMBER(curChar[2]) &&
IS_NUMBER(curChar[3]) &&
IS_NUMBER(curChar[4]) &&
IS_NUMBER(curChar[5]))
{
char hex[8] = {'0', 'x'};
hex[2] = curChar[2];
hex[3] = curChar[3];
hex[4] = curChar[4];
hex[5] = curChar[5];


int i;
StrToIntExA(hex, STIF_SUPPORT_HEX, &i);
wStr += (wchar_t)i;


curChar += 6;
}
else
{
wStr += (wchar_t)*curChar;
curChar++;
}
}


if (wStr.size())
{
return wStr;
}


return L"";
}