Skip to content

Instantly share code, notes, and snippets.

@rep-movsd
Created May 16, 2016 19:08
Show Gist options
  • Save rep-movsd/a2573df2b8328c6323a5dc025c6da207 to your computer and use it in GitHub Desktop.
Save rep-movsd/a2573df2b8328c6323a5dc025c6da207 to your computer and use it in GitHub Desktop.
Naive string tokenizer
vector<string> split(string s)
{
vector<string> sRet;
size_t i = 0;
do
{
string sWord;
// Find beginning of a word
while(i < s.size() && s[i] == ' ') ++i;
// Accumulate chars until end of a word or the input
while(i < s.size() && s[i] != ' ')
{
sWord += s[i];
i++;
}
// If we have a word save it
if(!sWord.empty())
sRet.push_back(sWord);
}
while(i < s.size());
return sRet;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment