I am parsing a string in C++ using the following:
using namespace std;
string parsed,input=\"text to be parsed\";
stringstream input_stringstream(input);
i
Answer is already there, but selected-answer uses erase function which is very costly, think of some very big string(in MBs). Therefore I use below function.
vector split(const string& i_str, const string& i_delim)
{
vector result;
size_t found = i_str.find(i_delim);
size_t startIndex = 0;
while(found != string::npos)
{
result.push_back(string(i_str.begin()+startIndex, i_str.begin()+found));
startIndex = found + i_delim.size();
found = i_str.find(i_delim, startIndex);
}
if(startIndex != i_str.size())
result.push_back(string(i_str.begin()+startIndex, i_str.end()));
return result;
}