String slice and index : slice « String « Ruby






String slice and index


s = 'My kingdom for a string!'
s.slice(3)                         # => 107
s[3]                               # => 107
107.chr                            # => "k"
s.slice(3,1)                       # => "k"
s[3,1]                             # => "k"

 








Related examples in the same category

1.Slice a string
2.Negative index in slice