Char[] confusing

Robert Fraser fraserofthenight at
Tue Mar 3 01:13:30 PST 2009

Qian Xu wrote:
> Lutger wrote:
>> s[4] means the fifth element of s[]
>> s[0..4] is a slice from the first to the fifth, but not including the 
>> fifth element. The last element in a slice is always one past the end 
>> of that slice.
> Thank you both.
> I have to do math in mind in order to keep my code correct ;-)
> IMO, it does not make any sense.
> s[start..end]
>   end - is neither the count of characters in the array slice,
>            nor the end index of the slice.
>         it is just the index after the real end character.

It's the same way it is in Python, etc. Also, it makes a lot of things 
easier, i.e.:

s[0..x] is x characters long
s[x..$] is everything from index x to the end of the string

More information about the Digitalmars-d-learn mailing list