Hello ! I am having some problems when i try to make a problem. It consists in erasing all the multiple white spaces and just leaving 1 space for each word.
This is the text: HelloMyName______isDelshire._______ Take de '' as white spaces. I managed to get the 'inner' multiple spaces but i do not know how to erase the ones at the beginning and at the end. This is what i did:
#include <string>
#include <iostream>
using namespace std;
class Foo
{
public:
void removeDoubleSpaces( string t )
{
int i;
i = t.find(" ");
string ch;
if ( i > -1 )
{
ch = t.replace( i,2," " );
removeDoubleSpaces (ch);
}
else if ( i == -1 )
{
cout << t << endl;
}
}
};
int main()
{
Foo bar;
bar.removeDoubleSpaces(" Hi my user is Delshire , what's yours?. ");
cin.get();
return 0;
}
I need to make the beginning and the ending with no spaces, with my code i have 1 space and it should not be like that
Thanks!