Hello. So, suppose I had a string, "Hello.World" and I wanted
to get from that, "Hello" and "World". How can I do this easily?
Last edited on
Nice C++ solution there, dutch, using std::string and C++ functions.
If the delim is a single character, then consider:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
auto split(const std::string& str, char delim)
{
std::istringstream iss(str);
std::vector<std::string> vs;
for (std::string s; std::getline(iss, s, delim); vs.push_back(std::move(s)));
return vs;
}
int main()
{
const std::string str {"one.two.three.four.five"};
const auto v {split(str, '.')};
for (const auto& s : v)
std::cout << s << '\n';
}
| |
Last edited on