Skip to content

Instantly share code, notes, and snippets.

@ashwinrs
Last active July 17, 2017 15:48
Show Gist options
  • Save ashwinrs/c6a4a3e6ecd05509db112bf39f7d601f to your computer and use it in GitHub Desktop.
Save ashwinrs/c6a4a3e6ecd05509db112bf39f7d601f to your computer and use it in GitHub Desktop.
String tokenizer in C++
// Based on - https://stackoverflow.com/a/53878/437894
#include <vector>
#include <string>
using namespace std;
vector<string> stringTokenizer(string input, char delimiter){
vector<string> result;
if(!input.length())
return result;
const char *it = input.c_str();
do {
const char *cstart = it;
while(*it && *it != delimiter)
it++;
result.push_back(string(cstart, it));
} while(*it++);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment