hi,
i need a solution.
I have a string which contains some thing like
string str = "my , name . is ' heman`th";
i need to extract the invidual words into an array or vector based on the delimiters.
delimiters in my case are ( , ' ` , . and space)
Is there any way of doing this using a function instead of manually.
hemanth.avs
inline std::vector < std::string > split(const std::string &s, const char *by = " ")
{
std::vector < std::string > res;
res.reserve(2);
const unsigned int SIZE = s.size();
unsigned int i(0);
unsigned int j(0);
for (i = 0; i <= SIZE; i = j + 1)
{
for (j = i; j < SIZE && strchr(by, s[j]) == NULL; j++)
{;}
res.push_back(s.substr(i, j-i));
}
return res;
}
I think you can rewrite it for yourself
Last edited on