loading...

Skip the first line of a file in D

github logo 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;
data.popFront();

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.

twitter logo DISCUSS
Classic DEV Post from Feb 1

What is your morning routine?

So I wanted to try and do at least a post a week, and I didn't have much time to prepare one this wee...

Jesse Phillips profile image
Long time solo programmer. Building CI/CD and having the opportunity to improve collaboration.

Sore eyes?

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️

(There is also a pink mode)