码迷,mamicode.com
首页 > 其他好文 > 详细

字符串分割函数

时间:2017-06-04 13:54:22      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:size   字符   star   color   pat   pattern   back   art   ack   

 

//字符串分割函数
vector<string> split(string str, string pattern){
    vector<string> ret;
    if (pattern.empty()) return ret;
    size_t start = 0, index = str.find_first_of(pattern, 0);
    while (index != str.npos){
        if (start != index)
            ret.push_back(str.substr(start, index - start));
        start = index + 1;
        index = str.find_first_of(pattern, start);
    }
    if (!str.substr(start).empty())
        ret.push_back(str.substr(start));
    return ret;
}

 

字符串分割函数

标签:size   字符   star   color   pat   pattern   back   art   ack   

原文地址:http://www.cnblogs.com/haiyang21/p/6940211.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!