mario::konrad
programming / C++ / sailing / nerd stuff
C++ String Split
© 2005 / Mario Konrad

Splits a specified string into a container of a certain type.

Examples, also split works well with join.

1
2
3
std::vector<std::string> v;
utils::split(v, "a:b:c:d:ef:ghi", ":");
std::cout << utils::join(v.begin(), v.end()) << std::endl;
1
2
3
std::list<std::string> v;
utils::split(v, "a:b:c:d:ef:ghi", ":");
std::cout << utils::join(v.begin(), v.end()) << std::endl;
1
2
3
std::list<std::string> v = utils::split<std::list<std::string> >(
    "a:b:c:d:ef:ghi", ":");
std::cout << utils::join(v.begin(), v.end()) << std::endl;
1
2
3
std::vector<int> v;
utils::split(v, "1:2:3:4:56:789::abc", ":");
std::cout << utils::join(v.begin(), v.end()) << std::endl;