Qian Xu wrote:
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 might help to think of the indexes in a slice as numbering the
Qian Xu:
> I have to do math in mind in order to keep my code correct ;-)
> IMO, it does not make any sense.
At the beginning you have to think a bit about it, but you quickly learn it,
and you find it's the best way to design it :-)
Several languages use this same convention.
It allows you to s
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 corre
grauzone wrote:
> Think of it as "everything in the string before this."
I tend to think of a indexes as referring to the positions between the
characters instead of the characters themselves.
"ABCD" -> 0 'A' 1 'B' 2 'C' 3 'D' 4
's[a..b]' = the elements betweens positions 'a' and 'b'.
's[a]' = t
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 corre
On Tue, 03 Mar 2009 02:03:23 +0300, BCS wrote:
Reply to Qian,
Hi,
I am confusing with getting sub-string of a char[].
[..]
My question is: why s[4]=E, but s[0..4]=ABCD (without E)
Having the fist number be included and the second not works better than
the other options.
Consider w
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,
Reply to Qian,
Hi,
I am confusing with getting sub-string of a char[].
[..]
My question is: why s[4]=E, but s[0..4]=ABCD (without E)
Having the fist number be included and the second not works better than the
other options.
Consider what would have to change to make these work for the
Qian Xu wrote:
> Hi,
>
> I am confusing with getting sub-string of a char[].
>
> - code -
> module main;
>
> import tango.io.Console;
> import tango.text.convert.Integer;
>
> void main()
> {
>char[] s = "ABCDE"; // 5 chars
>int le