Optional quotes in file hosting

My recent project requires me to read the csv file. People refer me to file workers because "you should not reinvent the game." However, the documentation is really crap, I can't find a way to handle the extra quotes. Here is my csv:

2734000585,IDR,04/04/2016,04/04/2016,0000000,1010,SETOR TUNAI,"783275305006511 VENDY",,"820,000.00","5,820,000.00"

I am not the one who generated the above csv, this is from the bank. As you can see, their csv file sucks and has a serious problem. Some strings are enclosed in quotation marks, some are not. In addition, currency values ​​are encoded as a string.

I made a class for it:

using System;
using FileHelpers;

[DelimitedRecord(",")]

public class ImporBii
{
    public long RekNum;

    public string Currency;

    [FieldConverter(ConverterKind.Date, "dd/MM/yyyy")]
    public DateTime TransDate;

    [FieldConverter(ConverterKind.Date, "dd/MM/yyyy")]
    public DateTime RecordDate;

    public string Unused1;

    public int TransCode;

    public string TransCodeStr;

    public string Keterangan;

    [FieldConverter(ConverterKind.Decimal, "#,##0.00")]
    public decimal Debet;

    [FieldConverter(ConverterKind.Decimal, "#,##0.00")]
    public decimal Kredit;

    [FieldConverter(ConverterKind.Decimal, "#,##0.00")]
    public decimal Saldo;
}

I thought the file wizards are smart enough to see quotes on their own, but the result is a complete disaster. Please help me.: - (

+4
1

[FieldQuoted()] ,

[DelimitedRecord(",")]
public class ImporBii
{
    public long RekNum;

    public string Currency;

    [FieldConverter(ConverterKind.Date, "dd/MM/yyyy")]
    public DateTime TransDate;

    [FieldConverter(ConverterKind.Date, "dd/MM/yyyy")]
    public DateTime RecordDate;

    public string Unused1;

    public int TransCode;

    public string TransCodeStr;

    [FieldQuoted('"', QuoteMode.OptionalForBoth)]
    public string Keterangan;

    [FieldConverter(ConverterKind.Decimal, ".")]
    [FieldQuoted('"', QuoteMode.OptionalForBoth)]
    public decimal? Drebet;

    [FieldConverter(ConverterKind.Decimal, ".")]
    [FieldQuoted('"', QuoteMode.OptionalForBoth)]
    public decimal? Kredit;

    [FieldConverter(ConverterKind.Decimal, ".")]
    [FieldQuoted('"', QuoteMode.OptionalForBoth)]
    public decimal? Saldo;
}
+2

All Articles