#pragma once
|
#include <afx.h>
|
#include <string>
|
#include <locale>
|
#include <codecvt>
|
#include <iostream>
|
#include <sstream>
|
#include <iomanip>
|
using namespace std;
|
|
class StringUtil {
|
|
public:
|
static string wstringToString(wstring wt) {
|
wstring_convert<codecvt_utf8<wchar_t>> 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;
|
}
|
|
static string to_string(double val) {
|
std::stringstream stream;
|
stream << std::fixed << std::setprecision(2) << val;
|
return stream.str();
|
}
|
|
static bool isNumber(const std::string& str) {
|
for (char c : str) {
|
if (!isdigit(c)) {
|
return false;
|
}
|
}
|
return true;
|
}
|
};
|