csvReader read file byLine()?
Jesse Phillips
jessekphillips+D at gmail.com
Thu Jun 21 19:42:11 PDT 2012
On Thursday, 21 June 2012 at 20:30:07 UTC, Jens Mueller wrote:
>> >auto file = File(filename, "r");
>> >auto records = csvReader!(Record)(file.byLine());
>> >
>> >Am I missing something? Was this left out for a reason or an
>> >oversight?
>> >
>> >Jens
>>
>> You might make use of std.algorithm.joiner.
>
> The problem is that csvParser expects a range with elements of
> type
> dchar. Any idea why that is required for CSV parsing?
>
> Jens
It requires a dchar range so that Unicode support is enforced. It
is the same reason char[] is a range of dchar.
You'll have to give me some example code, my test has no issue
using joiner with byLine.
import std.stdio;
import std.algorithm;
import std.csv;
void main()
{
struct Record {
string one, two, three;
}
auto filename = "file.csv";
auto file = File(filename, "r");
auto records = csvReader!Record(file.byLine().joiner("\n"));
foreach(r; records)
{
writeln(r);
}
}
More information about the Digitalmars-d
mailing list