5

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

first = 4
last = 11
replacement = '...'
'show me the money'.replace_part(first, last, replacement)
# => 'show...money'
4

1 回答 1

17
str = 'show me the money'
first = 4
last = 11
replacement = '...'
str[first..last] = replacement
str 
#=> 'show...money'
于 2013-11-01T17:36:18.910 回答