the types that each of the elements in the line should be returned as
the name of the file to read
the format string to use when reading
If only one type is passed, then an array of that type. Otherwise, an array of std.typecons.Tuples.
Exception if the format string is malformed. Also, throws Exception if any of the lines in the file are not fully consumed by the call to std._format.formattedRead. Meaning that no empty lines or lines with extra characters are allowed.
import std.typecons : tuple; scope(exit) { assert(exists(deleteme)); remove(deleteme); } write(deleteme, "12 12.25\n345 1.125"); // deleteme is the name of a temporary file // Load file; each line is an int followed by comma, whitespace and a // double. auto a = slurp!(int, double)(deleteme, "%s %s"); assert(a.length == 2); assert(a[0] == tuple(12, 12.25)); assert(a[1] == tuple(345, 1.125));
Reads a file line by line and parses the line into a single value or a std.typecons.Tuple of values depending on the length of Types. The lines are parsed using the specified format string. The format string is passed to std._format.formattedRead, and therefore must conform to the format string specification outlined in std._format.