Skip to content

Instantly share code, notes, and snippets.

@ilpropheta
Created January 1, 2017 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilpropheta/6b7a3941f96884df6a5416ee7c39ea39 to your computer and use it in GitHub Desktop.
Save ilpropheta/6b7a3941f96884df6a5416ee7c39ea39 to your computer and use it in GitHub Desktop.
vector<string> split(const string& str, const char* delims)
{
vector<string> ret;
string::size_type start = 0;
auto pos = str.find_first_of(delims, start);
while (pos != string::npos)
{
if (pos != start)
{
ret.push_back(str.substr(start, pos - start));
}
start = pos + 1;
pos = str.find_first_of(delims, start);
}
if (start < str.length())
ret.push_back(str.substr(start, str.length() - start));
return ret;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment