DEV Community

Jesse Phillips
Jesse Phillips

Posted on • Updated on

Skip the first line of a file in D

There are actually a number of ways to do this, which can depend on your objectives. I want to leave you with

import std.file;
import std.string;

auto data = readText("filename").lineSplitter;
data.popFront();
Enter fullscreen mode Exit fullscreen mode

But this reads in the entire content into memory first. And that does not match the Python behavior I was working with.

import std.stdio;
import std.string;

auto data = File("filename", "r");
data = data.findAmong(["\n", "\r\n"]);
data.skipOver("\n", "\r\n");
Enter fullscreen mode Exit fullscreen mode

There is actually a really nice io library called iopipe in the works. In my opinion it is very low level and wouldn't create a simpler example. But I have not gone beyond reading the docs.

And that concludes the series on Python. I will be starting a new series next week in the same spirit.

Top comments (1)

Collapse
 
aberba profile image
Lawrence Aberba

Looking to try iopipe myself in my exploration journey