1std::vector<std::string> split_string(const std::string& str,
2 const std::string& delimiter)
3{
4 std::vector<std::string> strings;
5
6 std::string::size_type pos = 0;
7 std::string::size_type prev = 0;
8 while ((pos = str.find(delimiter, prev)) != std::string::npos)
9 {
10 strings.push_back(str.substr(prev, pos - prev));
11 prev = pos + 1;
12 }
13
14 // To get the last substring (or only, if delimiter is not found)
15 strings.push_back(str.substr(prev));
16
17 return strings;
18}
19