Can you read the next line while iterating over byLine?

Daniel Kozak via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 2 12:26:36 PST 2017


Dne 2. 2. 2017 20:35 napsal uživatel "John Doe via Digitalmars-d-learn" <
digitalmars-d-learn at puremagic.com>:

On Thursday, 2 February 2017 at 18:58:46 UTC, Daniel Kozak wrote:

> Even this one could works:
>
> import std.stdio;
>
> void main(string[] args)
> {
>     auto range = File("text.txt").byLine();
>
>     foreach (line; range)
>
>     {
>         if (line != "")
>         {
>             writeln(line);
>             range.popFront;
>             char[] url = range.front().dup;
>             range.popFront;
>             char[] num = range.front().dup
>         }
>     }
> }
>

Thanks readln is perfect. Since I am calling readln in different places and
I always need to remove the newline character I have line=line[0..$-1] all
over my code. Is there are better way?


you can use popBack on readln od trim but it is not more elegant. Maybe
open enhancement on issues.dlang.org to phobos to add parametr for not
keeping line end char

unrelated second question: Why is there no split function with a maxsplit
parameter?


what is maxsplit parametr, I have never use it od need it?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20170202/d1b59c07/attachment.html>


More information about the Digitalmars-d-learn mailing list