#pragma once #include #include #include #include #include using namespace std; class StringUtil { public: static string wstringToString(wstring wt) { wstring_convert> conv; string result = conv.to_bytes(wt); return result; } static std::wstring Unescape(const std::string& input) { std::wstring wresult; for (size_t i = 0; i < input.length(); ) { if (input[i] == '\\' && input[i + 1] == 'u') { std::string code = input.substr(i + 2, 4); wchar_t unicode = stoi(code, nullptr, 16); wresult += unicode; i += 6; } else { wresult += input[i++]; } } return wresult; } static std::string cstring2String(CString getbuf) { int iLen = WideCharToMultiByte(0, 0, getbuf, -1, NULL, 0, NULL, NULL); //Ê×ÏȼÆËãTCHAR ³¤¶È¡£ char* chRtn = new char[iLen * sizeof(char)]; //¶¨ÒåÒ»¸ö TCHAR ³¤¶È´óСµÄ CHAR ÀàÐÍ¡£ WideCharToMultiByte(0, 0, getbuf, -1, chRtn, iLen, NULL, NULL); //½«TCHAR ÀàÐ͵ÄÊý¾Ýת»»Îª CHAR ÀàÐÍ¡£ std::string str(chRtn); return str; } };