Created
November 5, 2015 20:18
-
-
Save ch-hristov/a4a6ca3b384a06a18add to your computer and use it in GitHub Desktop.
Split string by delimiter C++
This file contains hidden or 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
std::vector<std::string> split(const std::string &text, char sep) { | |
std::vector<std::string> tokens; | |
int start = 0, end = 0; | |
while ((end = text.find(sep, start)) != std::string::npos) { | |
tokens.push_back(text.substr(start, end - start)); | |
start = end + 1; | |
} | |
tokens.push_back(text.substr(start)); | |
return tokens; | |
} | |
//link http://stackoverflow.com/a/7408245/4487530 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment