Last active
April 1, 2018 16:14
-
-
Save tyabu12/2db204c469717348d9f8 to your computer and use it in GitHub Desktop.
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 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