您的位置:首页 > 编程语言 > C语言/C++

C++用string类写split方法

2015-09-21 11:17 281 查看
void Split(const std::string& s,
const std::string& delim,
std::vector<std::string>* ret) {
size_t last = 0;
size_t index = s.find_first_of(delim, last);
while (index != std::string::npos) {
ret->push_back(s.substr(last, index-last));
last = index + 1;
index = s.find_first_of(delim, last);
}
if (index - last > 0) {
ret->push_back(s.substr(last, index - last));
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: