Skip to content

Instantly share code, notes, and snippets.

@SolemnJoker
Created November 7, 2020 06:22
Show Gist options
  • Save SolemnJoker/a3b3d9f4e9a91f547f05e25822f89a08 to your computer and use it in GitHub Desktop.
Save SolemnJoker/a3b3d9f4e9a91f547f05e25822f89a08 to your computer and use it in GitHub Desktop.
split a string
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