比较2个文本文件的差异,在日志文件中输出差异摘要

问题描述 投票:0回答:1

因此,我有6个不同的文本文件,我想根据用户选择要比较的内容来相互比较。我的程序已经比较了文本文件,并给出了文本文件相同还是不同的输出。我现在想能够添加它的功能,说出它在哪些行号上不同,以及添加/删除了哪些字符。

我这样初始化了字符串数组:'''string [] texta''''''string [] textb''''''string [] textc'''等。

假设string []数组中已经有文本,就像我自己做的那样:'''texta = System.IO.File.ReadAllLines(@“ texta.txt”);'''

c# text-files diff
1个回答
0
投票
StreamReader obj1;
            StreamReader obj2;

            obj1 = new StreamReader(@"texta.txt");
            obj2 = new StreamReader(@"textb.txt");


            string Text1;
            string Text2;
            int line=0;
            while (!obj1.EndOfStream || !obj2.EndOfStream)
            {
                Text1 = obj1.ReadLine();
                Text2 = obj2.ReadLine();

                if (Text1 != Text2)
                {
                    break;
                }
                else
                    line++;
            }

            // line = line Nr. not the same
© www.soinside.com 2019 - 2024. All rights reserved.