split
vector<string> split(const string& str, const string& delim) {
vector<string> res;
if(str.empty()) return res;
char * strs = new char[str.length() + 1];
strcpy(strs, str.c_str());
char * d = new char[delim.length() + 1];
strcpy(d, delim.c_str());
char *p = strtok(strs, d);
while(p) {
res.push_back(string(p));
p = strtok(NULL, d);
}
return res;
}
trim
string trim(const string& s){
if (s.empty()) return s;
int stPos = s.find_first_not_of(" ");
if(stPos == string::npos) return "";
return s.substr(stPos, s.find_last_not_of(" ") + 1);
}
startsWith/endsWith
bool startsWith(const string& s, const string& sub){
return s.find(sub) == 0;
}
bool endsWith(const string& s, const string& sub){
return s.rfind(sub) == (s.length()-sub.length());
}