On 02/12/2012 09:37 AM, RenatoL wrote: > Loosing my time on skittles... > > input "abcd" > desired output "arcd" > i want to use stride > > snippet, where x and y are integer in real code: > > string s1 = "abcd"; > s1 = s1[stride(s1,x)..y] ~ 'r' ~ s1[2..$]; > > if x = 0 and y = 0 -> run time error. ok > if x = 0 and y = 1 -> "rcd" (??) > if x = 1 and y = 0 -> run time error. ok > if x = 1 and y = 1 -> "rcd" > if x = 0 and y = 2 -> "brcd" (WTF?) > if x = 1 and y = 2 -> "brcd" (...) > > what the hell of parameters have i to put to achieve "arcd"?
This is yet another problem caused by the dual nature of narrow strings. When used with algorithms like stride(), a char[] is *not* a RandomAccessRange but when used with the [] operator it is.
According the stride()'s documentation, s1 will lose elements through popFront() because of not being a RandomAccessRange.
Related question: Does D define the order of evaluation in an expression like
foo() ~ bar() Or is it unspecified as in C and C++? Ali