digitalmars.D.learn - funny behavior of ".."
- seany (4/4) Aug 08 2014 The .., range operator, when used like this :
- Dominikus Dittes Scherkl (9/13) Aug 08 2014 Yes. [..] is exclusive the last element.
The .., range operator, when used like this : string a = "abcd"; string b = a[0 .. a.count()-1]; sets b to "abc". is this the expected behavior?
Aug 08 2014
On Friday, 8 August 2014 at 15:17:25 UTC, seany wrote:The .., range operator, when used like this : string a = "abcd"; string b = a[0 .. a.count()-1]; sets b to "abc". is this the expected behavior?Yes. [..] is exclusive the last element. So [0..1] is a single element [0] That allows to avoid to always writing the "-1". BTW: you can even use $ instead of a.count(): string b = a[0..$]; And if you like to slice the whole string, leave even the backets out: string b = a;
Aug 08 2014