logo CodeStepByStep logo

replaceAll

Language/Type: C++ string return
Related Links:

Write a function named replaceAll that accepts three parameters: a string s, and two character (char) values c1 and c2, and returns a new string that is equal to s but with each occurrence of c1 replaced by c2.

For example, the call of replaceAll("Hello, world!", 'l', 'Y') should return "HeYYo, worYd!".

Do not call any of the following string member functions: find, rfind, indexOf, contains, replace, split. Also do not call the Stanford library function stringReplace in your solution.

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.