Esempio n. 1
0
 public void lineByLine(readFile FileLargest, readFile FileSmallest, int count)
 {
     if (count >= FileSmallest.linesInFile.Count)  // If count is larger than the total lines in the smallest file, then just print the larger file
     {
         Console.WriteLine($"{FileLargest.linesInFile[count].line_}");
     }
     else
     {
         line LineLongest  = FileLargest.linesInFile[count];
         line LineShortest = FileSmallest.linesInFile[count];
         if (FileSmallest.linesInFile[count].line_.Length > FileLargest.linesInFile[count].line_.Length)
         {
             LineLongest  = FileSmallest.linesInFile[count];
             LineShortest = FileLargest.linesInFile[count];
         }
         int innerCount = 0;
         foreach (char i in LineShortest.line_) // To stop it comparing against numbers larger than the shortest line (there is still a try-catch later to aid this)
         {
             try
             {
                 if (FileLargest.linesInFile[count].line_[innerCount] != FileSmallest.linesInFile[count].line_[innerCount])
                 {
                     same = false;
                     Console.ForegroundColor = ConsoleColor.Red;
                     Console.Write($"{FileLargest.linesInFile[count].line_[innerCount]}"); // Check line by line, then do a more thorough char by char check (less instructions are executed this way)
                     Console.ForegroundColor = ConsoleColor.White;
                 }
                 else
                 {
                     Console.Write($"{FileLargest.linesInFile[count].line_[innerCount]}");
                 }
                 innerCount++;
             }
             catch
             {
                 // Runs if one line is longer than the other.
             }
         }
     }
 }
Esempio n. 2
0
 public char[] fileDataAnalysis = { };               // This is public as it will be checked later.
 public readFile(string fileName)
 {
     try
     {
         using (StreamReader a = new StreamReader(fileName))
         {
             string line_;
             while ((line_ = a.ReadLine()) != null) // Reads line by line
             {
                 fileData = fileData + line_;       // Adds to a string.
                 line t = new line();               // Adds line to list, lists only have one attribute, which is a string so its not too hard.
                 t.line_ = line_;
                 linesInFile.Add(t);
             }
         }
         fileDataAnalysis = fileData.ToCharArray();
     }
     catch (Exception e)
     {
         Console.WriteLine("The file could not be read."); // If the file isn't there, tell the user.
     }
 }