I have been playing around with these two functions for a bit, dunno if this is practical though. I have only been learning c++C++ for a a couple of days, coming from a javaJava background.
There we had a function that does this for us,us; I tried making something similar.
#include <iostream>
#include <string>
#include <vector>
using namespace std;
vector<string>parse(string test, string Deli);
int main()
{
vector<string> x = parse("random text to test splitting apart ", " ");
// note , the deliminator have to be after the text not before it.
for (string &e : x)
{
cout << e << endl;
}
return 0;
}
vector<string>parse(string test, string Deli) {
int count = 0; int token = 0;
vector<string>parsed;
for (size_t i = 0; i <= count; i++)
{
string x = (test.substr(token, test.find(Deli, token)-token));
parsed.push_back(x);
token += test.find(Deli, token +1) - (token-1);
test.find(Deli, token) != std::string::npos ? count++ : count;
}
return parsed;
}