Skip to content

Instantly share code, notes, and snippets.

@zhuker
Created February 22, 2023 18:01
Show Gist options
  • Save zhuker/0457afe9cc044d7aa41659cae29c2989 to your computer and use it in GitHub Desktop.
Save zhuker/0457afe9cc044d7aa41659cae29c2989 to your computer and use it in GitHub Desktop.
split string
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