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#比较两个文本文件并生成一个有差异的新文件


- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 输入按键事件处理程序 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01