Skip to content

Instantly share code, notes, and snippets.

@shawnfeng0
Created March 2, 2021 05:59
Show Gist options
  • Save shawnfeng0/1b3362f4bee8427296beb9e028f87b74 to your computer and use it in GitHub Desktop.
Save shawnfeng0/1b3362f4bee8427296beb9e028f87b74 to your computer and use it in GitHub Desktop.
string split function for C++
#include <vector>
#include <string>
inline std::vector<std::string> Split(const std::string &s, const std::string &delimiters = " ") {
std::vector<std::string> tokens;
std::string::size_type start = s.find_first_not_of(delimiters, 0);
std::string::size_type end = s.find_first_of(delimiters, start);
while (std::string::npos != end || std::string::npos != start) {
tokens.emplace_back(s.substr(start, end - start));
start = s.find_first_not_of(delimiters, end);
end = s.find_first_of(delimiters, start);
}
return tokens;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment