Advertisement
Wolfrost

C++ Basic string tokenizer

Nov 27th, 2016
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. std::vector<std::string> get_tokens(std::string str, char start_delim = '<', char end_delim = '>')
  2. {
  3.     unsigned int first = 0, last = 0;
  4.     std::vector<std::string> tokens {};
  5.  
  6.     while (first != std::string::npos) {
  7.         first = str.find(start_delim);
  8.         last = str.find(end_delim);
  9.         tokens.push_back(str.substr(first+1,last-first-1));
  10.         str = str.substr(last, std::string::npos);
  11.     }
  12.  
  13.     return tokens;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement