1.txt的内容为:
888888
777777
666666
555555
...
..
.
2.txt的内容为:
123456
888888
879789
555555
...
..
.
----------------------
分别读取2个TXT文件,取得她们的交集,接着输出到C盘,请问如何做?

解决方案 »

  1.   

    将两个txt按照你规定的方式截取字符串存到数组中   对数组中的数据进行比较,相同的输出就行了
      

  2.   

    读取文件到数组中,linq中有取交集、并集、差集方法,很方便。
    如果你这2个文件都是大文件,无法直接读取到内存,那就只能一行行的读第一个文件,把读到的值去第二个文件中搜索
      

  3.   


    string[] s1 = ...
    string[] s2 = ...
    string[] s0 = (from str1 in s1 select str1).Intersect(from str2 in s2 select str2).ToArray();
      

  4.   

    贴完整的 string[] arr1 = File.ReadAllLines(@"C:\1.txt", Encoding.GetEncoding("GB2312"));
     string[] arr2 = File.ReadAllLines(@"C:\3.txt", Encoding.GetEncoding("GB2312"));
    string[] arr0 = (from str1 in arr1 select str1).Intersect(from str2 in arr2 select str2).ToArray();
     File.WriteAllLines(@"C:\2.txt",arr0);