Guest User

CompareLoadOrder File

a guest
Feb 22nd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7.  
  8. namespace CompareLoadOrder
  9. {
  10.     class Program
  11.     {      
  12.         static void Main(string[] args)
  13.         {
  14.  
  15.             //get a buffer to return to zero
  16.             Stream s = new MemoryStream();
  17.  
  18.             //our three files.
  19.             StreamReader alpha= new  StreamReader(@"alpha.txt");
  20.             StreamReader beta= new  StreamReader(@"beta.txt");
  21.             StreamWriter output = new  StreamWriter(@"output.txt");
  22.  
  23.             //internal listing so we can mess with data
  24.             List<string> alphaList = new List<string>();
  25.             List<string> betaList = new List<string>();
  26.             List<string> outputList = new List<string>();
  27.  
  28.             //fill alphaList
  29.             for (int i = 0; i < File.ReadLines(@"alpha.txt").Count(); i++)
  30.             {
  31.                 string newData = alpha.ReadLine();
  32.                 alphaList.Add(newData);
  33.             }
  34.  
  35.             //fill betaList
  36.             for (int i = 0; i < File.ReadLines(@"beta.txt").Count(); i++)
  37.             {
  38.                 string newData = beta.ReadLine();
  39.                 betaList.Add(newData);
  40.             }
  41.  
  42.             //return the readers back to index 0, start of file
  43.             s.Position = 0;
  44.             alpha.DiscardBufferedData();
  45.             beta.DiscardBufferedData();
  46.  
  47.             //compare the two files. If any matches 100%, save the match to outputList
  48.             for (int i = 0; i < File.ReadLines(@"alpha.txt").Count(); i++)
  49.             {
  50.                 for (int j = 0; j < File.ReadLines(@"beta.txt").Count(); j++)
  51.                 {
  52.                     if (alphaList[i].Equals(betaList[j]))
  53.                     {
  54.                         outputList.Add(alphaList[i]);
  55.                     }                    
  56.                 }
  57.             }
  58.  
  59.             //write the outputList to a new file.
  60.             for (int i = 0; i < outputList.Count(); i++)
  61.             {
  62.                 output.WriteLine(outputList[i]);
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment