Replace a substring : replace « String « Ruby






Replace a substring


speaker = "King Richard, 2007"
speaker[", 2007"]= "III" # => "III"
p speaker # => "King Richard III"

 








Related examples in the same category

1.The replace method replaces a string wholesale.
2.Use ERB to replace string