Challenge: Replace All Occurrences of a Character in a String

Write code to find and replace all occurrences of a specific character in a string.

Find all occurrences of a specific character in the string. Replace all occurrences of that character with another one:

  • Input: A string s, character a, and character b. Replace all occurrences of the character a stored in the string s with the value stored in b.

  • Output: Display all indices of the string where the character a is located and then print the modified string.

Get hands-on with 1400+ tech skills courses.