Skip to content

Instantly share code, notes, and snippets.

@ladyrick
Created August 12, 2018 08:11
Show Gist options
  • Save ladyrick/5e7ddb793f832c823efed55285bac0b3 to your computer and use it in GitHub Desktop.
Save ladyrick/5e7ddb793f832c823efed55285bac0b3 to your computer and use it in GitHub Desktop.
c++ string split()
vector<string> split(const string &str, const string &c) {
int start = 0;
int npos = str.find(c, start);
vector<string> result;
while (start < str.length() && npos != str.npos) {
result.push_back(str.substr(start, npos - start));
start = npos + c.length();
npos = str.find(c, start);
}
result.push_back(str.substr(start, str.length() - start));
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment