A place for my personal musings, about programming, design or whatever come across my mind

Array rediscovered

And so I always understand it wrongly,

1
2
s = "hello"
s[0,2] = "He"

That I thought the second operand is the ending index, and that somehow it works like range, where

1
2
a = [1,2,3]
a[0...2] = [1,2]

So, the last index is excluded from the result, it ranged from index 0 up till index 2, but index 2 itself is not included.

Only now I know that the second operand in retrieving substring from an array is actually the length that we specified for the substring, and the first operand is the starting index.

So, it now make more sense for me.

Leave A Comment