c# Compare two text files and generate a new one with differences(c#比较两个文本文件并生成一个有差异的新文件)
问题描述
我正在寻找快速比较 2 个文本文件(+-15000 行)并获得两个文件中不同的输出字符串的最佳方法.第一个是旧库存,新库存是当前库存,我想生成第三个,其中包含 file2 & 之间不同的字符串文件 1.(这 2 个文件中有 95% 是相似的).
I am looking for the best way to compare 2 text files (+-15000lines) quickly and get as output strings that are differents in the two files. 1st one is an old inventory, new one is the current inventory and I would like to generate an third one containing strings that are different between file2 & file1. (95% of the 2 files will be similar).
推荐答案
很简单的方法,假设similar的意思是equal:
Very simple approach, assuming that similar means equal:
var file1Lines = File.ReadLines(file1Path);
var file2Lines = File.ReadLines(file2Path);
IEnumerable<String> inFirstNotInSecond = file1Lines.Except(file2Lines);
IEnumerable<String> inSecondNotInFirst = file2Lines.Except(file1Lines);
您可以使用 foreach
来枚举行.
You can use foreach
to enumerate the lines.
这篇关于c#比较两个文本文件并生成一个有差异的新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:c#比较两个文本文件并生成一个有差异的新文件


基础教程推荐
- JSON.NET 中基于属性的类型解析 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01