title: C# compare two string arrays
body: <p>I've got two files</p>
  
  <p>"Database.txt" contains the following names:</p>
  
  <ol>
  <li>Dog  </li>
  <li>Cat  </li>
  <li>Mouse  </li>
  <li>Panda  </li>
  <li>Bear  </li>
  </ol>
  
  <p>"Slave.txt" contains the following names:</p>
  
  <p>Cat<br>
  Panda  </p>
  
  <p>I want to compare the "Slave.txt" with "Database.txt" and create third file with:</p>
  
  <pre>
  2. Cat  
  4. Panda  
  </pre>
  
  <p>(Cat and Panda from Slave.txt find in Database.txt)</p>
  
  <p>My code:</p>
  
  <pre><code>static void Main(string[] args)
      {
          String directory = @"C:\Users\user\Desktop\";
          String[] linesA = File.ReadAllLines(Path.Combine(directory, "Database.txt"));
          String[] linesB = File.ReadAllLines(Path.Combine(directory, "Slave.txt"));
          IEnumerable&lt;String&gt; onlyB = linesB.Intersect(linesA);
          File.WriteAllLines(Path.Combine(directory, "Result.txt"), onlyB);
      }
  </code></pre>
  
  <p>works only on Database.txt structure like:</p>
  
  <p>Dog<br>
  Cat<br>
  Mouse<br>
  Panda<br>
  Bear  </p>
  
  <p>without line numbers.
  Is there somethink instead .Intersect to find only part of string, not full string?</p>