G
Gary Yngve
First the docs:
...If passed two Fixnum objects, returns a substring starting at the
offset given by the first, and a length given by the second. If given
a range, a substring containing characters at offsets given by the
range is returned... Returns nil if the initial offset falls outside
the string, the length is negative, or the beginning of the range is
greater than the end.
Now from irb (1.8):
Seems to me like the null terminator of the string is somehow getting
muddled into all of this.
Is there any meaning/purpose behind this behavior?
Thanks,
Gary
...If passed two Fixnum objects, returns a substring starting at the
offset given by the first, and a length given by the second. If given
a range, a substring containing characters at offsets given by the
range is returned... Returns nil if the initial offset falls outside
the string, the length is negative, or the beginning of the range is
greater than the end.
Now from irb (1.8):
=> nil"foo"[2..2] => "o"
"foo"[3..3] => "" # ????????
"foo"[4..4]
=> nil"foo"[2,1] => "o"
"foo"[3,1] => "" # ????????
"foo"[4,1]
=> nil # This makes sense to me, but seems inconsistent wrt the above"foo"[2] => 111 # (the 'o' char)
"foo"[3]
Seems to me like the null terminator of the string is somehow getting
muddled into all of this.
Is there any meaning/purpose behind this behavior?
Thanks,
Gary