C++ 字符串分割

来源:互联网 发布:千牛卖家版mac不能用 编辑:程序博客网 时间:2024/05/01 17:04


最近遇到了字符串的分割,自己参考了其他的做法,总结了下,

对于sep为单个字符是稳定的,但是对于多个就会出错,因为内部使用的是find_first_of

ErrCode SplitCsv(const string& src, const string& sep, vector<string>& dest){if (src.empty())return Err_StrEmpty;dest.clear();string subStr;string::size_type start(0), index(0);while (1){index = src.find_first_of(sep, start);subStr = src.substr(start, index - start);dest.push_back(subStr);start = src.find_first_not_of(sep, index);if (start == string::npos)break;}return No_Err;}


0 0
原创粉丝点击