vendredi 29 mai 2015

Comparing strings of text files

I have three text files: file1 file2 and file3 all of which contain emails. file1 is supposed to have all the emails in there, file2 has all emails that are A-M, and file 3 have emails from n-z (This is not important but I figure it would help give a little context.)

I am writing a console application program in c# that will look at these three files, and if there is an email that is not 1 that where it should be, then it will write to a masterfile that will say what needs to be added to what.

For example, lets say I have the email ill27@hotmail.com (this is not my email it is just an example.) If it is found in file1 but not in file2, the output of the masterfile needs to be "this email needs to be added to file2: ill27@hotmail.com". Now if it was reversed, and the email was found in file2 but not in file1, then the output should be "this email needs to be added to file1: ill27@hotmail.com"

As part of my code, the answer I am looking for needs to be in some sort of foreach loop and if statements, however I am a little lost in what I need to put in. If someone could please help me in figuring out what it is I have to use in my statements I would very much appreciate it. If someone has a question about any of this please feel free to ask!

        //Making a list for file1
        List<string> listFullPack = new List<string>();
        string line;
        StreamReader sr = new StreamReader("file1");
        while ((line = sr.ReadLine()) != null)
        {
            listFile1.Add(line);
        }
        sr.Close();

        //Making a list for file2
        List<string> listDen1 = new List<string>();
        string line1;

        StreamReader sr1 = new StreamReader("file2");
        while ((line1 = sr1.ReadLine()) != null)
        {
            listFile2.Add(line1);
        }
        sr1.Close();

        //Making a list for file3
        List<string> listDen2 = new List<string>();
        string line2;

        StreamReader sr2 = new StreamReader("file3");
        while ((line2 = sr2.ReadLine()) != null)
        {
            listFile3.Add(line2);
        }
        sr2.Close();


        //This will double check that emails are in
        foreach (string element in listFullPack)
        {
            System.Console.WriteLine(element);
            Debug.WriteLine(element);

            if (element == "jimbob@hotmail.com")
            {

                Debugger.Break();
            }

        }

        //this will compare the file1 list to the file2 list
        var firstNotSecond = listFile1.Except(listFile2).ToList();
        var secondNotFirst = listFile2.Except(listFile1).ToList();

        //this will compare the file2 list to the file3 list
        var firstNotThird = listFile1.Except(listFile3).ToList();
        var thirdNotFirst = listFile3.Except(listFile1).ToList();

        //this will compare the file2 list to the file3 list
        var secondNotThird = listFile2.Except(listFile3).ToList();
        var thirdNotSecond = listFile3.Except(listFile2).ToList();

        foreach (string element in listFile1) // This is where I am lost

        {

            if (!)
            {

            }
        }


    }
}
        }

Aucun commentaire:

Enregistrer un commentaire