如何通过其他字符串将子字符串从某个字符替换为另一个字符?
first = 4
last = 11
replacement = '...'
'show me the money'.replace_part(first, last, replacement)
# => 'show...money'
答案 0 :(得分:14)
str = 'show me the money'
first = 4
last = 11
replacement = '...'
str[first..last] = replacement
str
#=> 'show...money'