Created
November 7, 2020 06:22
-
-
Save SolemnJoker/a3b3d9f4e9a91f547f05e25822f89a08 to your computer and use it in GitHub Desktop.
split a string
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
inline | |
std::vector<std::string> split(const std::string& str, char seperator) { | |
std::vector<std::string> results; | |
std::string::size_type start = 0; | |
std::string::size_type sep = str.find(seperator); | |
while (sep != std::string::npos) { | |
if (start < sep) | |
results.emplace_back(str.substr(start, sep - start)); | |
start = sep + 1; | |
sep = str.find(seperator, start); | |
} | |
if (start != str.size()) | |
results.emplace_back(str.substr(start)); | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment