Splitting a range into a range of tuples

Adam via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 1 15:31:37 PDT 2015


Hi,

I have a string of pairs of integers, where pairs are delimited 
from each other by commas, and members of the pair are delimited 
by a space. I'd like to end up with something like a range of 
2-tuples, which I can then sort with a lambda. I'm running into 
problems trying to do this, after splitting on commas:

Tuple!(int,int) coord = to!(int[])(splitter(pairString," 
").array[]);

...which may not even be a good idea, I don't know. I've been 
following D for a long time, but this is the first time I've 
tried to actually use it; this seems like the kind of thing that 
should take just a few lines, if only I knew the libraries and 
range concepts well enough.

To be clear, this is what I have:

"192 14, 301 3, 578 0, 0 17"

...and this is what I want:

[(578,0),(301,3),(192,14),(0,17)]

What's the best way to do this? Should I be using map!() 
somewhere?

Thanks,
Adam


More information about the Digitalmars-d-learn mailing list