enter a range to indicate a range of characters you want to change. Include the last character with two dots (..) : String Range « String « Ruby






enter a range to indicate a range of characters you want to change. Include the last character with two dots (..)


speaker = "This is a test. This is a test. This is a test. This is a test. This is a test. "
speaker[13..15]= "This is a test. " # => "the Third"
p speaker # => "King Richard the Third"

 








Related examples in the same category

1.enter a string as the argument to []=, and it will return the new, corrected string, if found; nil otherwise.
2.Get substring from a string object
3.Getting the Parts of a String You Want
4.String range with string.length
5.Generating a Succession of Strings
6.Change a string with range