FileHelpers: Optional fields in non-quoted CSV

江枫思渺然 提交于 2019-12-22 09:01:05

问题


I am using FileHelpers to import data from a CSV file. Problem is, some versions of the CSV file have more fields than others.

As such, I have marked the fields that are sometimes missing as being optional, but this does not seem to work as instead of just ignoring when fields are missing (which it seems to do ok) it is also always chopping the last character off of the last field that is present.

For example...

  • a row containing "ABC,DEF,GHI" (without the quotes) imports as "ABC", "DEF" & "GHI"
  • a row containing "ABC,DEF" (again without the quotes) imports as "ABC" & "DE"

My record format is defined as follows...

[DelimitedRecord(@",")]
public class RecordFormat {

    [FieldTrim(TrimMode.Both)]
    public String FirstValue;

    [FieldTrim(TrimMode.Both)]
    public String SecondValue;

    [FieldOptional]
    [FieldTrim(TrimMode.Both)]
    public String OptionalValue;

}

Can anybody suggest what it is I am missing?

Thanks.


回答1:


Look like a bug in which seems to be fixed in the latest version 2.9.9

See link at http://www.filehelpers.com/forums/



来源:https://stackoverflow.com/questions/10656409/filehelpers-optional-fields-in-non-quoted-csv

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!