Reading files using delimiters/terminators

Jesse Phillips Jesse.K.Phillips+D at gmail.com
Sun Dec 27 02:41:12 UTC 2020


On Sunday, 27 December 2020 at 00:13:30 UTC, Rekel wrote:
> I'm trying to read a file with entries seperated by '\n\n' 
> (empty line), with entries containing '\n'. I thought the 
> File.readLine(KeepTerminator, Terminator) might work, as it 
> seems to accept strings as terminators, since there seems to 
> have been a thread regarding '\r\n' seperators.
>
> I don't know if there's some underlying reason, but when I try 
> to use "\n\n" as a terminator, I end up getting the entire file 
> into 1 char[], so it's not delimited.
>
> Should this work or is there a reason one cannot use byLine 
> like this?
>
> For context, I'm trying this with the puzzle input of day 6 of 
> this year's advent of code. (https://adventofcode.com/)

Unfortunately std.csv is character based and not string. 
https://dlang.org/phobos/std_csv.html#.csvReader

But your use case sounds like splitter is more aligned with your 
needs.

https://dlang.org/phobos/std_algorithm_iteration.html#.splitter


More information about the Digitalmars-d-learn mailing list