how to skip empty field in csvReader?

mw mingwu at gmail.com
Tue Jun 6 05:09:35 UTC 2023


Hi,

https://run.dlang.io/is/9afmT1

```
void main()
{
     import std.csv;
     import std.stdio: write, writeln, writef, writefln;
     import std.algorithm.comparison : equal;
     string text = "Hello;65;;\nWorld;123;7.5";
     struct Layout
     {
         string name;
         int value;
         double other;
     }

     auto records = text.csvReader!Layout(';');
     assert(records.equal([
         Layout("Hello", 65, 2.5),
         Layout("World", 123, 7.5),
     ]));


}
```

There is an empty field in the 1st line: "Hello;65;;", then

std.csv.CSVException@/dlang/dmd/linux/bin64/../../src/phobos/std/csv.d(1232): Floating point conversion error for input "".

Is there a way to tell csvReader to skip such empty fields?

Or, is there another CSV reader library with this functionality I 
can use?


Thanks.



More information about the Digitalmars-d-learn mailing list