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 10:24:43 PST 2017


There is a readln function, and this is not forum but just web frontend
around mailing list. http://forum.dlang.org/help#about

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

> Let's say you're trying to parse a file format like:
>
> Name
> http://example.com
> 123234
>
> Foo Bar
> http://dlang.org
> 888888
>
> with blocks separated by varying amount of blank lines.
>
> -----
> import std.stdio;
>
> void main(string[] args){
>     auto range = File("text.txt").byLine();
>
>     foreach( line; range ){
>         if (line != ""){
>             writeln(line);
>             // char[] url = range.???
>             // char[] num = range.???
>         }
>     }
> }
> -----
> How can you read the next line while iterating over a file line by line,
> so that the next iteration uses the line after next? If this isn't possible
> byLine is a design flaw and D should instead provide a regular readLine
> function.
>
> btw: What is this? A forum for a programming language that doesn't support
> code blocks?
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20170202/860c9d2f/attachment-0001.html>


More information about the Digitalmars-d-learn mailing list