字符串切分

bool split_str(const string& s, const string& delim, vector<string>* ret)
{
    int last = 0;
    int index = s.find_first_of(delim, last);
    int length = s.size();
    int end = string::npos;
    while (index != end){
        ret->push_back(s.substr(last, index - last));
        last = index + 1;
        index = s.find_first_of(delim, last);
    }
    if (length > last){
        ret->push_back(s.substr(last, index - last));
    }
    return true;
}

 

posted @ 2017-05-26 16:01  我就是熊吉  阅读(354)  评论(0编辑  收藏  举报