如何用另一个子串替换子串(通过索引from..to)

fre*_*oid 3 ruby string

如何通过其他字符串将子字符串从某个字符替换为另一个字符?

first = 4
last = 11
replacement = '...'
'show me the money'.replace_part(first, last, replacement)
# => 'show...money'
Run Code Online (Sandbox Code Playgroud)

fre*_*oid 15

str = 'show me the money'
first = 4
last = 11
replacement = '...'
str[first..last] = replacement
str 
#=> 'show...money'
Run Code Online (Sandbox Code Playgroud)