/* Create a function that takes a string, removes all "special" characters * (e.g. ! @ # $ % ^ & \ *) and returns the new string. The only * non-alphanumeric characters allowed are dashes -, underscores _ and spaces. */ std::string removeSpecialCharacters(std::string str) { std::string::iterator it = str.begin(); for(;it!=str.end();it++){ // check character in string to see if it is alphanumeric bool alpha = isalnum(*it); bool notdash = *it != '-'; bool notunderscore = *it != '_'; bool notspace = *it != ' '; // if a non-alphanumeric character is found, remove it from the string. // do not remove the character if it is a space, underscore or dash. if(alpha==false && notdash && notunderscore && notspace){ str.erase(it); it--; } } return str; }