Reading files using delimiters/terminators
Steven Schveighoffer
schveiguy at gmail.com
Tue Dec 29 14:50:41 UTC 2020
On 12/26/20 7:13 PM, 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/)
Are you on Windows? If so, your double newlines might be \r\n\r\n,
depending on what editor you used to create the input. Use a hexdump
program to see what the newlines are in your input file.
Now, you would think that the underlying C stream would do this for you.
I'm not sure how it works exactly, as I don't use Windows.
-Steve
More information about the Digitalmars-d-learn
mailing list