str.replace()
str.replace(oldvalue, newvalue)
Method description
- Input:
- oldvalue : String
- The string to replace.
- newvalue : String
- The string to replace the old value with.
- Returns:
- The string with the replaced terms.
- Return Type:
- String
txt = "I like potato, wanna mash my potato, won't you mash your potato with me?"
txt.replace("avocado", "potato")
"I like avocado, wanna mash my avocado, won't you mash your avocado with me?"
# Replace is often used to remove white space.
txt = "Remove All The Space Here! "
txt.replace(" ", "")
"RemoveAllTheSpaceHere!"
Problems or suggestions about this page? Fill out our feedback form.