0

CSVHelper and FileHelper is not an option

I have a .csv export that I need to check for consistency structured like the below

Reference,Date,EntryID

ABC123,08/09/2015,123

ABD234,08/09/2015,124

XYZ987,07/09/2015,125

QWE456,08/09/2016,126

I can use ReadLine or RealAllLines and .Split which give me entire rows/columns BUT I have need to select each row and then go through each attribute (separated by ',') for format checking

I am running into problems here. I can not single out each value in a row for this check. It is probably either something simple onto

 class Program
{
    static void Main(string[] args)
    {
        string csvFile = @"proof.csv";
        string[] lines = File.ReadAllLines(csvFile);


        var values = lines.Skip(1).Select(l => new { FirstRow = l.Split('\n').First(), Values = l.Split('\n').Select(v => int.Parse(v)) });
        foreach (var value in values)
        {
            Console.WriteLine(string.Format("{0}", value.FirstRow));
        }
    }
}

Or I am going down the wrong path, my searches relate to pulling specific rows or columns (as opposed to checking the individual values associated)

The sample of the data above has a highlighted example: The date is next year and I would like to be able to proof that value (just an example as it could be in either column where errors appear)

4

2 回答 2

2

我不能连续挑出每个值

那是因为你分裂了\n两次。,一行中的值用逗号 ( )分隔。

我不确定 LINQ 应该做什么,但它就像这样简单:

string[] lines = File.ReadAllLines(csvFile);

foreach (var line in lines.Skip(1))
{
    var values = line.Split(',');
    // access values[0], values[1] ...
}
于 2015-09-08T10:33:59.383 回答
0

Instead of reading it as text read it by OLEDB object, so data of CSV file will come in datatable and you do not need to spit it.

To Read the csv file you can use these objects of OLEDB

System.Data.OleDb.OleDbCommand 
System.Data.OleDb.OleDbDataAdapter
System.Data.OleDb.OleDbConnection

and

System.Data.DataTable
于 2015-09-08T10:44:47.230 回答