Beispiel #1
0
        /// <summary>
        /// Metoda porównuje oba pliki CSV z pominięciem ich nagłówków
        /// </summary>
        /// <param name="f1">First file to compare</param>
        /// <param name="f2">Second file to compare</param>
        /// <returns> [commonPart, f1 only part, f2 only part] table</returns>
        public static CSVFile[] Compare(CSVFile f1, CSVFile f2)
        {
            CSVFile commonPart = new CSVFile("");
            CSVFile f1Part     = new CSVFile("");
            CSVFile f2Part     = new CSVFile("");
            int     found      = 0;

            //Zał: f2 musi być większy od f1

            //Jeśli nie jest - zamieniamy pliki
            if (f2.Record.Count < f1.Record.Count)
            {
                CSVFile temp = f1;
                f1 = f2;
                f2 = temp;
            }

            for (int i = 0; i < f1.Record.Count; i++)
            {
                if ((found = f2.records.FindIndex(x => x.Equals(f1.records[i]))) >= 0)
                {
                    commonPart.Record.Add(f1.records[i]);
                    //f1.Record.Remove(f1.Record[i]);
                    f2.Record.RemoveAt(found);
                }
                else
                {
                    f1Part.Record.Add(f1.records[i]);
                    //f1.Record.Remove(f1.Record[i]);
                }
            }
            foreach (CSVRecord rec in f2.Record)
            {
                f2Part.Record.Add(rec);
            }


            return(new CSVFile[] { commonPart, f1Part, f2Part });
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            CSVFile file1 = new CSVFile(@"C:\Users\Mariusz\Downloads\proba.csv");
            CSVFile file2 = new CSVFile(@"C:\Users\Mariusz\Downloads\proba2.csv");


            file1.Parse();
            file2.Parse();

            Console.WriteLine("Porównujemy:");
            Console.WriteLine("{0}", file1.Header);
            CSVFile[] result_tab = CSVFile.Compare(file1, file2);

            Console.WriteLine("Common Part:");
            foreach (CSVRecord rec in result_tab[0].Record)
            {
                Console.WriteLine("{0}", rec.ToString());
            }
            Console.WriteLine();

            Console.WriteLine("f1 part:");
            foreach (CSVRecord rec in result_tab[1].Record)
            {
                Console.WriteLine("{0}", rec.ToString());
            }
            Console.WriteLine();

            Console.WriteLine("f2 part:");
            foreach (CSVRecord rec in result_tab[2].Record)
            {
                Console.WriteLine("{0}", rec.ToString());
            }

            Console.WriteLine();

            List <int> lista1 = new List <int>();

            lista1.Add(1);
            lista1.Add(3);
            lista1.Add(5);

            List <MariuszInt> lista2 = new List <MariuszInt>();
            MariuszInt        mint1  = new MariuszInt(1);
            MariuszInt        mint3  = new MariuszInt(3);
            MariuszInt        mint5  = new MariuszInt(5);

            lista2.Add(mint1);
            lista2.Add(mint3);
            lista2.Add(mint5);

            List <string> list = new List <string>();
            string        s1   = "Hello";
            string        s2   = "Elo";

            list.Add(s1);
            list.Add(s2);

            Console.WriteLine("lista1 zawiera 3?: {0}", lista1.Contains(2));
            Console.WriteLine("lista2 zawiera 3 (MariuszInt): {0}", lista2.Exists(el => el.x == 3));
            Console.WriteLine("list zawiera Hello? : {0}", list.Contains("Hello"));
            Console.WriteLine("Czy 1 linijka pliku 1 i 1 pliku 2 to to samo?: {0}", file1.Record[0].Equals(file2.Record[0]));


            Console.ReadLine();
        }