Removing whitespace
Jul 7, 2010 at 6:05pm UTC
For some odd reason, my function isn't removing any whitespace. Can anyone see why?
1 2 3 4 5 6 7 8 9
string Manage::RemoveWhite(string &str) {
string final;
for (unsigned int i = 0; i < str.length(); i++) {
if (str[i] != ' ' ) {
final += str[i];
}
}
return final;
}
How its used:
cout << line << " - " << RemoveWhite(temp) << endl;
Jul 7, 2010 at 6:11pm UTC
I think that should work - are you sure your problem isn't in how it's being used? Does temp perhaps have tab characters that you are mistaking for spaces?
--Rollie
Jul 7, 2010 at 6:17pm UTC
now that i think of it, yes, it is a tab space, but how would i remove that?
Jul 7, 2010 at 6:20pm UTC
if (str[i] != ' ' && str[i] != '\t' ) {
:)
--Rollie
Jul 7, 2010 at 6:23pm UTC
Ahh, thank you, that did the trick!
Topic archived. No new replies allowed.