Apr26

【原创】使用STL来构造字符串split 和join方法

Author: leeon  Click: 8529   Date: 2012.04.26 @ 13:30:10 pm Category: c/c++

学了几天c++的STL基本语法,写的很搓,不过功能算是基本实现了,类似于php中的implode和explode


vector splitString(const string str,const string w){
vector arr;
string tmp;
long index = 0;
tmp = str;
while((index=tmp.find(w))!=str.npos){
arr.push_back( tmp.substr(0,index));
tmp = tmp.substr(index+1);
}
if(tmp==""){
return arr;
}
arr.push_back(tmp);
return arr;
}

string joinString(const vectorv, const string w){
if(v.empty()) return "";
string tmp="";

if(v.size()==1)
return v[0];

for(int i=0;i if(i==(v.size()-1)){
tmp +=v[i];
}else{
tmp +=v[i]+w;
}
}

return tmp;

}



TAG:   c++ stl php implode explode split join

    评论
    • 提交

    分类

    标签

    归档

    最新评论

    Abyss在00:04:28评论了
    Linux中ramdisk,tmpfs,ramfs的介绍与性能测试
    shallwe99在10:21:17评论了
    【原创】如何在微信小程序开发中正确的使用vant ui组件
    默一在09:04:53评论了
    Berkeley DB 由浅入深【转自架构师杨建】
    Memory在14:09:22评论了
    【原创】最佳PHP框架选择(phalcon,yaf,laravel,thinkphp,yii)
    leo在17:57:04评论了
    shell中使用while循环ssh的注意事项

    我看过的书

    链接

    其他

    访问本站种子 本站平均热度:8823 c° 本站链接数:1 个 本站标签数:464 个 本站被评论次数:94 次