… when I read that in “abcdefg”, f is the character at index -1, the last character .
page 521, first bullet. The problem is that the explanation starts with an inclusive range, “abcdefg”[1..3], then switches to excluding ranges. I suggest to use inclusive ranges :
so “abcdefg”[3..-2] returns “def”, since d is the character at index 3, and f is the character at index -2
Halfway ranges also work, so “abcdefg”[..-2] (or “abcdefg”[...-1]) returns all but the last character
and “abcdefg”[3..] returns everything from index 3 on (“abcdefg”[3...] including the last character could be seen as an anomaly)
Wow, not sure how I missed that. I think inclusive ranges are easier to understand here.
Changed to
"abcdefg"[4..-1] returns "efg", since e is the character at index f, and f is the character at index -1, the last character. Halfway ranges also work, so "abcdefg"[..-2] returns all but the last character, and "abcdefg"[3..] returns everything from index 3 on