string redactdigits Please help ThanX

can you help write the code for this, I have no clue?

// replace digits with #'s
// e.g. redactDigits( "4 pizzas and 87 beers" )
returns "# pizzas and ## beers"
string redactDigits( const string & s );

the numbers should be different all the time
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <algorithm>
#include <iostream>
#include <string>
#include <cctype>

std::string redactDigits(const std::string& text)
{
    std::string result(text);
    std::replace_if(result.begin(), result.end(), std::isdigit, '#');
    return result;
}

int main()
{
    std::cout << redactDigits("4 pizzas and 87 beers") << '\n';
}


Although, I suspect that's not the sort of implementation your instructor will be expecting.
thanks for the replay but the code doesn't work

the numbers should change to #
thanks for the replay but the code doesn't work

The code does work.

the numbers should change to #

The function returns a new string where the numbers are changed. Feel free to modify it to work on the original string if you'd like it to work that way.
Topic archived. No new replies allowed.