Posted on 2009-07-04 21:52
魔のkyo 阅读(273)
评论(0) 编辑 收藏 引用
vector<string> split(const string& s, const string& delim, bool keepEmptyParts = true)
{
vector<string> res;
string item;
for(int i=0;i<s.length();i++)
{
if(delim.find(s[i]) == string::npos )
{
item += s[i];
}
else
{
if(keepEmptyParts || !item.empty())
{
res.push_back(item);
item = "";
}
}
}
if(keepEmptyParts || !item.empty())
{
res.push_back(item);
item = "";
}
return res;
}
string join(const vector<string>& v, const string& delim, bool keepEmptyParts = true)
{
string res;
for(int i=0;i<v.size();i++)
{
res += v[i];
if( i < v.size()-1)
{
if(keepEmptyParts || !v[i].empty())
{
res += delim;
}
}
}
return res;
}
公司不能上网啊,好多东西新学习的东西都贴不到BLOG上来了,555