簡體   English   中英

Filehelpers CSV解析。 如何使用FieldQuoted屬性?

[英]Filehelpers CSV parsing. How to use FieldQuoted attribute?

我有一個看起來像這樣的CSV:

a,b,c
a,b,c
a,"b,c",d

我在帶有屬性的分隔類中標記第二個字段:

[FieldQuoted('"', QuoteMode.OptionalForBoth, MultilineMode.AllowForRead)]
public String ExchangeRate;

但是第3行仍然將“b,c”解析為2個單獨的值。

你知道我做錯了什么嗎?

謝謝

我看不出你的代碼有什么問題。 我剛檢查過:以下程序運行正常:

[DelimitedRecord(",")]
public class MyClass
{
    public string Field1;
    [FieldQuoted('"', QuoteMode.OptionalForBoth, MultilineMode.AllowForRead)]
    public string ExchangeRate;
    public string Field3;
}

class Program
{
    static void Main(string[] args)
    {
        var engine = new FileHelperEngine<MyClass>();
        string fileAsString = @"a,b,c" + Environment.NewLine +
                              @"a,b,c" + Environment.NewLine + 
                              @"a,""b,c"",d";
        MyClass[] validRecords = engine.ReadString(fileAsString);

        // Check the ExchangeRate values for rows 0, 1, 2 are as expected
        Assert.AreEqual("b", validRecords[0].ExchangeRate);
        Assert.AreEqual("b", validRecords[1].ExchangeRate);
        Assert.AreEqual("b,c", validRecords[2].ExchangeRate);

        Console.ReadKey();
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM