Advent-of-Code/2022/7/SplitStr.h

23 lines
474 B
C++

#ifndef ADVENT_DVEREB_SPLITSTR_H
#define ADVENT_DVEREB_SPLITSTR_H
#include <vector>
#include <string>
std::vector<std::string> SplitStr(std::string str, const std::string &delim)
{
std::vector<std::string> rtn;
for(auto split = str.find(delim); split != std::string::npos; split = str.find(delim))
{
rtn.push_back(str.substr(0, split));
str = str.substr(split + delim.size()); // chop off beginning
}
if(str.size())
rtn.push_back(str);
return rtn;
}
#endif