Last active
July 17, 2017 15:48
-
-
Save ashwinrs/c6a4a3e6ecd05509db112bf39f7d601f to your computer and use it in GitHub Desktop.
String tokenizer in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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