Sep 29, 2009

Parsing a comma separated string in C++

int split(const string& s, char c, vector& v) {

string::size_type i = 0;
string::size_type j = s.find(c);

while (j != string::npos) {

v.push_back(s.substr(i, j-i));
i = ++j;
j = s.find(c, j);

if (j == string::npos)
v.push_back(s.substr(i, s.length( )));

}

return v.size();
}

reference

5 comments:

Anonymous said...

upssss..........

Anonymous said...

You were visited with remarkable idea

Anonymous said...

Like attentively would read, but has not understood

Anonymous said...

What excellent words

Anonymous said...

All not so is simple, as it seems


I advise to you to come on a site where there is a lot of information on a theme interesting you. Will not regret. Hot Health

Cat

Ragdoll Cat         Persian Cat     Finish Cat