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

Jarrett Billingsley jarrett.billingsley at gmail.com
Mon Oct 13 10:18:15 PDT 2008


On Mon, Oct 13, 2008 at 12:13 PM, Robert Kosek
<robert.kosek at thewickedflea.com> wrote:
> Hi all,
>
> I'm working on Kata 9 of <codekata.pragprog.com>; thus far there have been
> interesting problems, but now I need scan functionality.
>
> How does Tango's LineIterator.scan() work?  I'm still very new to D, so I
> realize this is a template function and object, but I have no idea how to
> actually use the function in this case.  Can someone give me an exemplary
> snippet or explanation on how it works?
>
> Thanks,
> Robert
>

LineIterator.scan is really kind of an internal method, I'm not sure
why it's documented.  Most of the public interface to LineIterator is
in its base class, StreamIterator
(http://www.dsource.org/projects/tango/docs/current/tango.text.stream.StreamIterator.html).

There are really two ways to use a StreamIterator: the foreach way and
the next() way.

If you want to get all the lines of a stream, for instance, you can
use a foreach loop:

LineIterator lines = new LineIterator(...);
foreach(line; lines) { /* do something with each line */ }

Or, you can use the next() method:

for(auto line = lines.next(); line !is null; line = lines.next())
{ /* do something with each line */ }


More information about the Digitalmars-d-learn mailing list