C#中 - 如何比较两个不同的文本文件文本文件、不同、两个

2023-09-07 09:50:18 作者:啵啵桃汀

在,有两个文本文件的情况下:

  FileA.txt
测试
1234
测试


FileB.txt
测试
5667
池塘
 

和所有出现FileA.txt将从FileB.txt被删除,被输出到FileC.txt

所以FileC.txt内容如下:

  5667
池塘
 
文本分割程序 V1.0.0.0绿色免费版下载

解决方案

  File.WriteAllLines(FileC.txt
  。File.ReadAllLines(FileB.txt)除(File.ReadAllLines(FileA.txt)));
 

In the case that there were two text files:

FileA.txt
test
1234
testing


FileB.txt
test
5667
pond

and all occurrences in FileA.txt would be removed from FileB.txt, being output into FileC.txt

So FileC.txt would read:

5667
pond

解决方案

File.WriteAllLines("FileC.txt",
  File.ReadAllLines("FileB.txt").Except(File.ReadAllLines("FileA.txt")));