Reputation: 7436
For some reason most Ruby string functions work with predetermined substrings and patterns. I don't have any assumptions about the string's contents, but I need to just delete n chars from m-th position. How do I do that?
Upvotes: 0
Views: 92
Reputation: 33552
You can use slice!
str='Apple'
str.slice![1..3] #=> ppl
puts str
#=> Ae
Upvotes: 0
Reputation: 80085
str = "abcdefghij"
m = 4
n = 3
str.slice!(m,n) # => "efg"
p str # => "abcdhij"
Upvotes: 5