Comment #0 by bearophile_hugs — 2013-12-04T05:11:24Z
Given a "data.csv" file that contains:
1,2,3,4
5,6,7,8
9,10,11,12
13,14,15,16
With dmd 2.065alpha you can read its contents like this using csvReader:
void main() {
import std.stdio, std.csv, std.file;
"data.csv".readText.csvReader!int.writeln;
}
Output:
[[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]
If the file is large you can also read the lines lazily (same output):
void main() {
import std.stdio, std.csv, std.file, std.algorithm;
"data.csv".File.byLine.map!(r => r.csvReader!int.front).writeln;
}
But I think csvReader should also support reading lines lazily like this:
"data.csv".File.csvReader!int.writeln;
Or something like this:
"data.csv".File.byLine.csvReader!int.writeln;
Comment #1 by robert.schadek — 2024-12-01T16:19:22Z