Note: I am working using C++11 standard
I am looking to write a function that handles the following problem:
Given the following input: a,b,c I want it to print a and b and c
Given: a,b,c, I want it to print a and b and c and ""
Given: ,a I want it to print "" and a
Given , it should print "" and in case of empty string it shouldn't print anything
In other words I want to extract every value between two , plus to take care of the edges.
My current implementation is so buggy and I had edited it more than 8 times since I always find some edge cases.
void print(const string &command)
{
string vertex_title = "";
int i = 0;
while (i < command.lengh()) {
if (command[i] == ',') {
if (i==command.lengh()-1) return false;
std::cout<<vertex_title;
vertex_title = "";
i++;
continue;
}
vertex_title += command[i++];
}
Note: I don't know but maybe regex help here (I know nothing about it)