1

I'm having issues with creating a delimiter field using FileHelpers when parsing a .csv. I have this one line of data that is always crashing during a LINQ operation similar to the example of the filehelpers on their site.

The error comes up at where a column has quotes such as this row:

data1, data2, "data3a, data3b", data4

How do I remove the comma within the quotes and then remove the quotes for data3a and data3b?

That specific column in the .csv file has two things, but I can't figure what delimiter fields I should use for that.

If I'm unclear or this question was answered or not purposeful comment below.

Thank you very much.

EDIT: The code for the class

The row: 2010,NON-HISPANIC BLACK,MALE,"NEPHRITIS, NEPHROTIC SYNDROME AND NEPHROSIS",70,1

//delimiters, ignore first row, separate with comma
[DelimitedRecord(",")]
[IgnoreFirst()]
public class CauseofDeathClass
{

    public int Year { get; set; }
    public string Ethnicity { get; set; }
    public string Sex { get; set; }
    public string Cause_of_Death { get; set; }
    public int Count { get; set; }
    public int Percent { get; set; }

}
Royce
  • 189
  • 6
  • 18

1 Answers1

2

Use the FieldQuoted attribute. See here for the different QuoteMode options.

//delimiters, ignore first row, separate with comma
[DelimitedRecord(",")]
[IgnoreFirst()]
public class CauseofDeathClass
{    
    public int Year { get; set; }
    [FieldQuoted('"', QuoteMode.OptionalForBoth)]
    public string Ethnicity { get; set; }
    [FieldQuoted('"', QuoteMode.OptionalForBoth)]
    public string Sex { get; set; }
    [FieldQuoted('"', QuoteMode.OptionalForBoth)]
    public string Cause_of_Death { get; set; }
    public int Count { get; set; }
    public int Percent { get; set; }
}
shamp00
  • 11,106
  • 4
  • 38
  • 81