How do I use the Tango LineIterator.scan()?

Jarrett Billingsley jarrett.billingsley at gmail.com
Tue Oct 14 05:53:41 PDT 2008


On Mon, Oct 13, 2008 at 10:28 PM, Alexander Pánek
<alexander.panek at brainsware.org> wrote:
> 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

The third column can have spaces.  This will split on them too.  Not
to mention line.split() will allocate a new array every time it's
called ;)


More information about the Digitalmars-d-learn mailing list