分割string类字符串
vector<string> SplitStrA(string Text, string site) { vector<string> resultVec; char* c_str = new char[Text.size()]; memset(c_str, 0, (Text.size() + 1)); memcpy(c_str, &Text[0], Text.size()); char* c_str2 = new char[site.size()]; memset(c_str2, 0, (site.size() + 1)); memcpy(c_str2, &site[0], site.size()); char* c_str3 = strtok(c_str, c_str2); while (c_str3 != NULL) { resultVec.push_back(string(c_str3)); c_str3 = strtok(NULL, c_str2); } return resultVec; }
分割wstring类宽字符串
vector<wstring> SplitStrW(wstring Text, wstring site) { vector<wstring> resultVec; wchar_t* c_str = new wchar_t[Text.size()*2]; memset(c_str, 0, (Text.size()+1) * 2); memcpy(c_str, &Text[0], Text.size() * 2); wchar_t* c_str2 = new wchar_t[site.size()*2]; memset(c_str2, 0, (site.size()+1) * 2); memcpy(c_str2, &site[0], site.size() * 2); wchar_t* c_str3 = wcstok(c_str, c_str2); while (c_str3 != NULL) { resultVec.push_back(wstring(c_str3)); c_str3 = wcstok(NULL, c_str2); } return resultVec; }