Skip the first line of a file in D

jessekphillips profile image Jesse Phillips Updated on ・1 min read

Python (14 Part Series)

1) Boolean in D 2) Comments in D 3 ... 12 3) Raise Exceptions in D 4) Add to a List in D 5) Count of a List in D 6) String Contained in a String in D 7) Where did my string go in D 8) Case Insensitive in D 9) Add to a Dictionary in D 10) Check Dictionary has key in D 11) Filter a Dictionary in D 12) Split, Apply, Merge in D 13) Map Reduce in D 14) 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;

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");

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.


markdown guide

Looking to try iopipe myself in my exploration journey