How can I replace the double space into single space using C++
ex:
\"1 2 3 4 5\" => \"1 2 3 4 5\"
this is what I`ve done till no
In while loop of splitLines code, use this code.
while((loc = line.find(" ")) != std::string::npos) //Two spaces here
{
line.replace(loc,2," "); //Single space in quotes
}
cout << line << endl;
Thats it. I haven't tried it out, let me know if it works.
And as fred pointed out, use pass by reference in splitLines function. The above solution is sub-normal and is O(n^2) complexity. This one is better.
int loc = -1;
while((loc = line.find(" ",loc+1)) != std::string::npos) //Two spaces here
{
line.replace(loc,2," "); //Single space in quotes
}
cout << line << endl;