c#比较两个文本文件并生成一个有差异的新文件 [英] c# Compare two text files and generate a new one with differences

查看:23
本文介绍了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#比较两个文本文件并生成一个有差异的新文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆