freemanoid
freemanoid

Reputation: 14770

How to replace substring with another substring (by index from..to)

How I can replace substring from some character to another by other string?

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

Upvotes: 7

Views: 3197

Answers (1)

freemanoid
freemanoid

Reputation: 14770

str = 'show me the money'
first = 4
last = 11
replacement = '...'
str[first..last] = replacement
str 
#=> 'show...money'

Upvotes: 20

Related Questions