Created
February 22, 2023 18:01
-
-
Save zhuker/0457afe9cc044d7aa41659cae29c2989 to your computer and use it in GitHub Desktop.
split 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
void string_split(const std::string &s, const std::string &delim, std::deque<std::string> &out, int maxElements) { | |
auto start = 0U; | |
auto end = s.find(delim); | |
while (end != std::string::npos && out.size() < maxElements - 1) { | |
out.push_back(s.substr(start, end - start)); | |
start = end + delim.length(); | |
end = s.find(delim, start); | |
} | |
out.push_back(s.substr(start, s.length() - start)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment