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.
We'll cover the following
Find all occurrences of a specific character in the string. Replace all occurrences of that character with another one:
-
Input: A string
s
, charactera
, and characterb
. Replace all occurrences of the charactera
stored in the strings
with the value stored inb
. -
Output: Display all indices of the string where the character
a
is located and then print the modified string.
Get hands-on with 1200+ tech skills courses.