to replace the first occurrence, simply do the following:
str = "Hello World" str['Hello'] = 'Goodbye' # the result is 'Goodbye World'
you can even use regular expressions:
str = "I have 20 dollars" str[/\d+/] = 500.to_s
Nafaa Boutefer May 12 '14 at 4:32 a.m. 2014-05-12 04:32
source share