Created
August 12, 2018 08:11
-
-
Save ladyrick/5e7ddb793f832c823efed55285bac0b3 to your computer and use it in GitHub Desktop.
c++ string split()
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
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