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 に答える