自己写的分割字符串的函数
2016-07-12 20:34
260 查看
void splitString(const std::string &str, const std::string &separator, std::vector<std::string> &retList)
{
string::size_type pos=0;
string::size_type newPos=0;
retList.clear();
while( (newPos= str.find(separator,pos)) != string::npos)
{
// if not empty sub str. (skip repetition of separator )
if(newPos-pos>0)
retList.push_back(str.substr(pos, newPos-pos));
// skip token
pos= newPos+separator.size();
}
// copy the last substr
if( pos<str.size() )
retList.push_back(str.substr(pos, str.size()-pos));
}
{
string::size_type pos=0;
string::size_type newPos=0;
retList.clear();
while( (newPos= str.find(separator,pos)) != string::npos)
{
// if not empty sub str. (skip repetition of separator )
if(newPos-pos>0)
retList.push_back(str.substr(pos, newPos-pos));
// skip token
pos= newPos+separator.size();
}
// copy the last substr
if( pos<str.size() )
retList.push_back(str.substr(pos, str.size()-pos));
}
相关文章推荐
- HashMap—基本结构
- Scala 运算符
- 布局的调用
- Codeforces 360B + Codeforces 689C ( 二分 + DP )
- 【2012.03.3普及组】烤饼干
- ideaIU 16注册码分享
- MySQL分库分表总结
- 数据库创建
- kvm虚拟化技术应用实战
- HDU-1754-I Hate It(线段树 点更新求最值)
- POJ-1511 Invitation Cards( 最短路,spfa )
- 初步理解JS的事件机制
- json数据解析
- eclipse工程图标上有个红色感叹号
- QGraphicItem实现中心旋转
- Linux可执行文件的启动及命令行参数和环境变量的传递
- jsp-简单小程序(乘法表、)
- 极光推送
- poj 2418 简单Trie树
- 【经典算法】:并查集详解