How do I use the Tango LineIterator.scan()?
Alexander Pánek
alexander.panek at brainsware.org
Mon Oct 13 19:28:54 PDT 2008
Jarrett Billingsley wrote:
> import tango.text.Util;
> ...
> // using line as the line of text.
> auto firstSpace = line.locate(' '); // syntactic sugar for locate(line, ' ')
> auto secondSpace = line.locate(' ', firstSpace + 1);
> auto firstCol = line[0 .. firstSpace];
> auto secondCol = line[firstSpace + 1 .. secondSpace];
> auto thirdCol = line[secondSpace + 1 .. $]; // $ means line.length
>
> // now you can convert the columns as you please
auto columns = line.split(" ");
auto firstCol = columns[0];
auto secondCol = columns[1];
// ... that’s a tad shorter. :P
More information about the Digitalmars-d-learn
mailing list