On Thursday, 15 July 2021 at 18:08:45 UTC, Scotpip wrote:
Hi folks
Settling down to write my first app but have come to a grinding
halt. This is my first system-level language so I'm afraid I'll
be asking some naïve questions.
All I'm trying to do is read a text file with Windows line
endings into an array for line-by-line processing.
The relevant function appears to be
[std.stdio.File.byLine](https://dlang.org/library/std/stdio/file.by_line.html).
The default isn't breaking the lines properly, so I have to
pass in the line ending. But the signature has me baffled:
```
auto byLine(Terminator, Char) (
KeepTerminator keepTerminator = No.keepTerminator,
Terminator terminator = '\x0a'
)
if (isScalarType!Terminator);
auto byLine(Terminator, Char) (
KeepTerminator keepTerminator,
Terminator terminator
)
if (is(immutable(ElementEncodingType!Terminator) ==
immutable(Char)));
```
To specify the line ending, it appears to be asking for a type
"Terminator" which I can't find in the library. Doing the
obvious doesn't work:
```
// Err: cannot deduce function from argument types
myFile.byLine(`\r\n`);
```
Also, how would you specify the Char type as a parameter?
The examples are unenlightening as they only show the default
case, so any help would be much appreciated. Any wider tips on
how to read these cryptic signatures would be a bonus!
Sorry I'm on mobile right now so can't help much, but if you're a
beginner, please read the book "programming in D" by Ali Cehreli.
http://ddili.org/ders/d.en/
If you just want to learn about files for now, visit this link,
it contains a chapter of his book(regrettably it doesn't cover
your exact usecase but maybe ```readln``` might work out for you)
http://ddili.org/ders/d.en/files.html