Newbie: Error parsing csv file with very long lines

salvari via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Apr 23 04:39:42 PDT 2016


On Saturday, 23 April 2016 at 11:13:19 UTC, Nicholas Wilson wrote:
> On Saturday, 23 April 2016 at 10:57:04 UTC, salvari wrote:
>> Fixed!!!
>>
>> Thanks a lot. :-)
>>
>>
>> But I have to think about this. I don't understand the failure.
>
> stdin.byLine() reuses its buffer. so the old arrays in columns 
> point to the data in byLine's buffer and they get overwritten 
> by subsequent calls.
>
> Also if you're trying to parse csv check out std.csv
>
> from the docs
>
> string str = "Hello;65;63.63\nWorld;123;3673.562";
> struct Layout
> {
>     string name;
>     int value;
>     double other;
> }
>
> auto records = csvReader!Layout(str,';');
>
> foreach(record; records)
> {
>     writeln(record.name);
>     writeln(record.value);
>     writeln(record.other);
> }

Thanks for your clue on std.csv!

I think I will use it a lot. I totally missed it.


More information about the Digitalmars-d-learn mailing list