csvReader read file byLine()?
Jesse Phillips
jessekphillips+D at gmail.com
Fri Jun 22 07:21:13 PDT 2012
On Friday, 22 June 2012 at 08:12:59 UTC, Jens Mueller wrote:
> The last line throws a CSVException due to some conversion error
> 'Floating point conversion error for input "".' for the
> attached input.
>
> If you change the input to
> 3.0
> 4.0
> you get no exception but wrong a output of
> [[4], [4]]
> .
Yes, and it seems .joiner isn't as lazy as I'd have thought.
byLine() reuses its buffer so it will overwrite previous lines in
the file. This can be resolved by mapping a dup to it.
import std.stdio;
import std.algorithm;
import std.csv;
void main()
{
struct Record {
double one;
}
auto filename = "file.csv";
auto file = File(filename, "r");
auto input = map!(a => a.idup)(file.byLine()).joiner("\n");
auto records = csvReader!Record(input);
foreach(r; records)
{
writeln(r);
}
}
More information about the Digitalmars-d
mailing list