Files
algorithm-template/trick/split-text.cpp

13 lines
413 B
C++

#include <vector>
#include <string>
std::vector<std::string> split(std::string target, std::string pattern) {
std::vector<std::string> res;
size_t start = 0, next = 0;
while ((next = target.find(pattern, start)) != std::string::npos) {
res.push_back(target.substr(start, next - start));
start = next + pattern.length();
}
res.push_back(target.substr(start));
return res;
}