Skip to content

Instantly share code, notes, and snippets.

@tyabu12
Last active April 1, 2018 16:14
Show Gist options
  • Save tyabu12/2db204c469717348d9f8 to your computer and use it in GitHub Desktop.
Save tyabu12/2db204c469717348d9f8 to your computer and use it in GitHub Desktop.
void split(std::vector<std::string>& dst, const std::string& src,
const std::string& delimiter, bool ignore_empty = false)
{
std::size_t p1 = 0;
do {
std::size_t p2 = src.find(delimiter, p1);
if (p2 == src.npos)
p2 = src.size();
if (p2 != p1 || !ignore_empty)
dst.push_back(src.substr(p1, p2-p1));
p1 = p2 + delimiter.size();
} while (p1 <= src.size());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment