-1

在此处输入图像描述
我正在尝试在我的项目中实现 FILEHELPER 2.0,但是一些带有“”引用的 csv 文件面临问题。它显示错误(显示此错误日志)

**" LineNumber | LineString |ErrorDescription 2|"Symbol","Date","Expiry","Strike Price","Open","High","Low","Close","LTP","结算价“,“不。of contract","Turnover in Lacs","Open Int","Change in OI","Underlying Value "|长度不能小于零。-> 参数名称:长度不能小于零。-> 参数名称:长度 3|" **

我的代码是这样的:

   var engine = new FileHelperEngine<script>();
   engine.Options.IgnoreFirstLines = 1; // skipping the header line

   script[] res = engine.ReadFile("agile.csv");  <<<<< at this line error occred 

和我的课程文件:

     [DelimitedRecord(",")]
      public class script
    {
         [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
        public string Symbol;
         [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
        public string Date;
         [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
        public string Expiry;
         [FieldQuoted('"', QuoteMode.AlwaysQuoted)]

       ...
    }

和 csv 文件是 .

"交易品种","日期","到期","行权价","开盘价","最高价","最低价","收盘价","LTP","结算价","合约数量"," Lacs 的营业额","Open Int","OI 的变化","基础价值"

"漂亮","2012 年 8 月 31 日","2012 年 9 月 27 日","5400.00","56.00","56.90","38.05","44.45","43.55","44.45","281087 ","765592.77","4845150","1334150","5258.50"

4

1 回答 1

1

我看不出您的错误有任何原因:以下代码可以正常工作:

[DelimitedRecord(",")]
public class Script
{
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string Symbol;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string Date;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string Expiry;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string StrikePrice;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string Open;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string High;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string Low;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string Close;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string LTP;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string SettlePrice;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string NoOfContracts;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string TurnOverInLacs;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string OpenInt;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string ChangeInOI;
    [FieldQuoted('"', QuoteMode.AlwaysQuoted)]
    public string UnderlyingValue;
}

class Program
{
    static void Main(string[] args)
    {
        string input = @"""Symbol"",""Date"",""Expiry"",""Strike Price"",""Open"",""High"",""Low"",""Close"",""LTP"",""Settle Price"",""No. of contracts"",""Turnover in Lacs"",""Open Int"",""Change in OI"",""Underlying Value """ + Environment.NewLine +
            @"""NIFTY"",""31-Aug-2012"",""27-Sep-2012"","" 5400.00"","" 56.00"","" 56.90"","" 38.05"","" 44.45"","" 43.55"","" 44.45"","" 281087"","" 765592.77"","" 4845150"","" 1334150"","" 5258.50""";

        var engine = new FileHelperEngine<Script>();
        engine.Options.IgnoreFirstLines = 1; // skipping the header line

        Script[] validRecords = engine.ReadString(input);

        // Check the third record
        Assert.AreEqual("NIFTY", validRecords[0].Symbol);
        Assert.AreEqual("31-Aug-2012", validRecords[0].Date);
        Assert.AreEqual("27-Sep-2012", validRecords[1].Date);
        // etc...            

        Console.WriteLine("All assertions passed");
        Console.Read();
    }
}
于 2012-09-03T08:38:08.053 回答