Negative index in slice : slice « String « Ruby






Negative index in slice


s = 'My kingdom for a string!'
s.slice(-7,3)                      # => "str"
s[-7,6]                            # => "string"

 








Related examples in the same category

1.Slice a string
2.String slice and index