Skip to content

Instantly share code, notes, and snippets.

@inhzus
Created November 12, 2019 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inhzus/658819ace45d05f367bc672d4906b969 to your computer and use it in GitHub Desktop.
Save inhzus/658819ace45d05f367bc672d4906b969 to your computer and use it in GitHub Desktop.
split string
void split(const std::string &s,
const std::string &delim,
const std::function<void(const std::string &)> &f) {
std::string::size_type m{}, n{};
while (true) {
n = s.find(delim, m);
f(s.substr(m, n - m));
if (n == std::string::npos) {
break;
}
m = n + delim.size();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment