Search code examples
c#-4.0filehelperscsv

FileHelpers tab "\t" delimited reader


I am trying some very simple examples from http://www.filehelpers.net/ and they work as long as I use ; or , for delimiter. If i try delimit by tab space it throws exception.

The delimiter '\t' can´t be found after the field 'CustomterId' at line 2 (the record has less fields, the delimiter is wrong or the next field must be marked as optional).

C# class

[IgnoreEmptyLines(true), IgnoreFirst(1), DelimitedRecord(@"\t"), IgnoreFirst(0)]
public class Customer
{
    // Fields
    public bool Active;
    public int CustomerId;
    [FieldConverter(ConverterKind.Date, "ddMMyyyy")]
    public DateTime CustomerJoinded;
    [FieldTrim(TrimMode.Both), FieldQuoted('"')]
    public string CustomerName;
}

File to read:

CustomterId CusomterName    CustomerJoinded Active
1001    ABCD EDF    05052012    TRUE
1002    qwetqwt  15052013   FALSE
1003    wtqwtqwt    03052013     TRUE
1004    qwetwtqwet  04052013     FALSE
1005    gwrtgqwtqwt 05052013     TRUE
1006    rgherghrtqw4gz  07052013     FALSE
1007    wgwherhreh  08052013     TRUE
1008    sfagh34hq3h 09052013     FALSE
1009    wf2rgahasrg 12052013     TRUE
1010    sfgwe3g 05052013     FALSE
1011    fsfwrvg 05052013     TRUE
1012    ra34qbdfb   05052013     FALSE
1013    wtqwg   05052013     TRUE
1014    dsgag3  05052013    FALSE
1015    hgrh    05052013    TRUE
1016    werw    05052013    FALSE

Can you please tell me what is my problem here.


Solution

  • In your DelimitedRecord attribute you've written @"\t", but that syntax is for verbatim string literals, meaning it's equivalent to "\\t". Remove the @ to get it to parse actual tab characters.