Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <vector>
- #include <iostream>
- #include <assert.h>
- std::vector<std::string> split(const std::string &s)
- {
- typedef std::string::size_type pos_t;
- pos_t beg_pos, end_pos;
- const std::string delims("\t ;,.");
- std::vector<std::string> ret;
- beg_pos = s.find_first_not_of(delims);
- while(beg_pos != std::string::npos)
- {
- end_pos = s.find_first_of(delims, beg_pos);
- if(std::string::npos == end_pos)
- {
- end_pos = s.length();
- }
- ret.push_back(s.substr(beg_pos, end_pos-beg_pos));
- beg_pos = s.find_first_not_of(delims, end_pos);
- }
- return ret;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- std::string s("\tbo1.bo2 bobo3 a");
- std::vector<std::string> v = split(s);
- assert(v.size() == 4);
- assert(v[0] == "bo1");
- assert(v[1] == "bo2");
- assert(v[2] == "bobo3");
- assert(v[3] == "a");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment