Can you read the next line while iterating over byLine?
John Doe via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Feb 2 11:34:37 PST 2017
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?
unrelated second question: Why is there no split function with a
maxsplit parameter?
More information about the Digitalmars-d-learn
mailing list