| Author |
Message |
|
|
julapy
|
Posted: Wed Dec 23, 2009 8:04 am |
|
|
Joined: Mon Jan 19, 2009 7:02 amPosts: 214Location: sydney |
had to work out a way of splitting a string into seperate words, couldn't find a solution on the forum so thought id post. Code: vector<string> ofxStringUtil :: split ( const string& s, const string& delim, const bool keep_empty ) { vector<string> result; if(delim.empty()) { result.push_back( s ); return result; } string::const_iterator substart = s.begin(), subend; while (true) { subend = search(substart, s.end(), delim.begin(), delim.end()); string temp(substart, subend); if( keep_empty || !temp.empty() ) { result.push_back(temp); } if( subend == s.end() ) { break; } substart = subend + delim.size(); } return result; }
the above method will return a vector which you can then iterate through to get the seperate words. you can split the string by any delimeter you chose. L.
|
|
Top
|
|
|
arturo
|
Posted: Wed Dec 23, 2009 10:10 am |
|
|
| Site AdminJoined: Wed Apr 11, 2007 1:02 amPosts: 1192Location: barcelona |
hey
since 006 you have ofSplitString in ofUtils : )
|
|
Top
|
|
|
julapy
|
Posted: Wed Dec 23, 2009 10:47 am |
|
|
Joined: Mon Jan 19, 2009 7:02 amPosts: 214Location: sydney |
ha! my bad  i use the api on the wiki like a bible... will make sure to check the source also next time.
|
|
Top
|
|
|
|
All times are UTC
Users browsing this forum: No registered users and 1 guest
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum
|
|