For each character in string, if the character is not in valid_chars, replaces the character with substitutor.