.net 解析大型CSV文件并比较数据
是否有我在C#中使用的CSV解析器,并比较CSV文件 情景: 我有多个CSV文件,每个CSV文件有几百万行。我应该加载CSV并尽快完成比较。:) CSV文件1:.net 解析大型CSV文件并比较数据,.net,c#-4.0,.net,C# 4.0,是否有我在C#中使用的CSV解析器,并比较CSV文件 情景: 我有多个CSV文件,每个CSV文件有几百万行。我应该加载CSV并尽快完成比较。:) CSV文件1: Account Amount 1234 1 9999 66 CSV文件2: Account Amount 1234 2 9999 66 CSV文件3: Account Amount 1234 1 9999 66 CSV文件4: Account Amount 1234 10 9999
Account Amount
1234 1
9999 66
CSV文件2:
Account Amount
1234 2
9999 66
CSV文件3:
Account Amount
1234 1
9999 66
CSV文件4:
Account Amount
1234 10
9999 66
比较后,输出如下所示
Account File1Amt File2Amt File3Amt File4Amt Match?
1234 1 2 1 10 No
9999 66 66 66 66 Yes
一个想法可能是,将数据加载到数据库中,然后用SQL完成工作。使用Load Table函数,您可以在很短的时间内加载大量数据。如果无法使用数据库或没有足够的机器资源,您可以使用字典对象创建报告,大致如下:
public void CreateAccountReport()
{
Dictionary<int, AccountReport> accountReportCollection = new Dictionary<int, AccountReport>();
//read in file 1 and add records to dictionary...
//read in files 2,3,4 and update dictionary (when reading in file 4 set bool match)
}
public class AccountReport
{
public int AccountNumber { get; set; }
public int File1Amt { get; set; }
public int File2Amt { get; set; }
public int File3Amt { get; set; }
public int File4Amt { get; set; }
public bool Match { get; set; }
public AccountReport()
{
}
}
public void CreateAccountReport()
{
字典accountReportCollection=新字典();
//读取文件1并将记录添加到字典。。。
//读入文件2、3、4并更新字典(读入文件4时设置布尔匹配)
}
公开课会计报告
{
public int AccountNumber{get;set;}
public int File1Amt{get;set;}
public int File2Amt{get;set;}
public int File3Amt{get;set;}
public int File4Amt{get;set;}
公共布尔匹配{get;set;}
公共会计报告()
{
}
}
据我所知,没有任何内置于C#中或可用于执行此确切任务的工具。如果您有权访问数据库(SQL Server、MySql等),则可以将其加载到数据库中,并使用单个查询运行报告。根据您的编码方式和机器资源,您可以将所有CSV文件加载到字典中并生成报告。是。我不能用DB。我会试试你的建议。