Here's what I have so far:
string stripSymbols(string str) {
int stringSize = strlen(str.c_str());
for (int i = 0; i < stringSize; i++)
if (str[i] == 0x46)
str[i] = 0x32;
return str;
}
I know the ascii codes are probably wrong. That's part of the problem. But once I figure those out, I was thinking I could maybe put a switch in here for each symbol that would replace each symbol with an empty space.
Or better yet, I could have a for loop in my for loop that loops through a string of symbols and replaces any that match with the user's input with an empty space.
I have a couple ideas, but I was wondering if there was a more efficient way of doing this.
Update 1:
This code looks a little better and works:
string stripSymbols(string str) {
int stringSize = str.size();
for (int i = 0; i < stringSize; i++)
if (str[i] == '.')
str[i] = ' ';
return str;
}
But the replies offer a more efficient solution.
Update 2:
Solution inspired by Kerrek SB's reply:
char symbols [] = {'!', '?', ',', '\'', '.'};
int symbols_size = sizeof(symbols) / sizeof(char);
for (int j = 0; j < symbols_size; j++)
replace(str.begin(), str.end(), symbols[j], ' ');