函数声明:
bool Split(const std::string &str, std::vector<std::string> &ret, std::string sep = ",");
函数定义:
bool Split(const std::string &str, std::vector<std::string> &ret, std::string sep) {
if (str.empty()) {
return false;
}
std::string temp;
std::string::size_type begin = str.find_first_not_of(sep);
std::string::size_type pos = 0;
while (begin != std::string::npos) {
pos = str.find(sep, begin);
if (pos != std::string::npos) {
temp = str.substr(begin, pos - begin);
begin = pos + sep.length();
} else {
temp = str.substr(begin);
begin = pos;
}
if (!temp.empty()) {
ret.push_back(temp);
temp.clear();
}
}
return true;
}