csvReader: how to read only selected columns while the class Layout has extra field?

mw mingwu at gmail.com
Mon Oct 3 19:43:36 UTC 2022


On Monday, 3 October 2022 at 18:02:51 UTC, Salih Dincer wrote:
> On Sunday, 2 October 2022 at 19:48:52 UTC, mw wrote:
>> ```
>>         text.csvReader!Layout(["b","c","a"]);  // Read only 
>> these column
>> ```
>>
>> The intention is very clear: only read the selected columns 
>> from the csv, and for any other fields of class Layout, just 
>> ignore (with the default D .init value).
>
> Why don't you do this?  For example you can try the following?
>
>     ```d
>     import std.csv, std.math.algebraic : abs;
>
>      
>     string str = "a,b,c\nHello,65,63.63\n➊➋➂❹,123,3673.562";
>          struct Layout
>          {
>              int value;
>              double other;
>              string name;
>          }


You didn't get my question, please add:

```
int extra_field;  // un-comment to see the error
```

to the struct, then you will see the error.




More information about the Digitalmars-d-learn mailing list