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#比较两个文本文件并生成一个有差异的新文件
基础教程推荐
- C# 9 新特性——record的相关总结 2023-04-03
- 获取C#保存对话框的文件路径 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 将数据集转换为列表 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 如果条件可以为空 2022-01-01
