File.byLineCopy

auto byLineCopy(Terminator = char, Char = immutable char)(KeepTerminator keepTerminator = No.keepTerminator, Terminator terminator = '\n') if (isScalarType!Terminator)

Returns an input range set up to read from the file handle one line at a time. Each line will be newly allocated. front will cache its value to allow repeated calls without unnecessary allocations.

Note

Due to caching byLineCopy can be more memory-efficient than

File.byLine.map!idup.

The element type for the range will be Char[]. Range primitives may throw StdioException on I/O error.

Parameters

CharCharacter type for each line, defaulting to immutable char.
keepTerminatorUse Yes.keepTerminator to include the terminator at the end of each line.
terminatorLine separator ('\n' by default). Use newline for portability (unless the file was opened in text mode). Example: ---- import std.algorithm, std.array, std.stdio; // Print sorted lines of a file. void main() { auto sortedLines = File("file.txt") // Open for reading .byLineCopy() // Read persistent lines .array() // into an array .sort(); // then sort them foreach (line; sortedLines) writeln(line); } ----

See Also

auto byLineCopy(Terminator, Char = immutable char)(KeepTerminator keepTerminator, Terminator terminator) if (is(immutable ElementEncodingType!Terminator == immutable Char))

ditto