title: Specialized data processing in C# to find instances of words in a string in textfile
body: <p>I have an example plaintext file called <code>dat</code> located in my example directory <code>/var/log/application/</code>. The structure would be something like this:</p>
  <pre><code>Cat
  Dog
  Bird
  Fish
  </code></pre>
  <p>This is the data I want to analyze. I have a second file called <code>var</code> in the same directory containing a single line that says <code>I have a dog and a cat!</code>. With C#, I want to find the number of times words in <code>dat</code> are found in <code>var</code>. This should return a value of 2. To do this, I have written a mostly non-functional script in C# to explain my reasoning.</p>
  <pre><code>using System;
  using System.IO;
  using Systems.Collections.Generic;
  
  namespace Example
  {
       class Logic
       {
            static int instances;
            static int entries = GetDat();
  
            static string datpath = @&quot;/var/log/application/dat&quot;;
            static string varpath = @&quot;/var/log/application/var&quot;;
  
            static void Main(string[] args)
            {
                 for(i = 0; i &lt;= GetDat; i++)
                 {
                      // I made this up because I don't know how to explain it otherwise
                      if(word.in GetVar instance.in GetDat)
                      {
                           instances++
                      }
                      return 2;
                 }
            }
  
            static byte[] GetDat()
            {
                 // Get entries from `dat` and turn it into array
            }
  
            static byte[] GetVar()
            {
                 System.Collections.Generic.IEnumerable&lt;String&gt; lines = File.ReadLines(varpath);
            }
       }
  }
  </code></pre>
  <p>How would I do this? Is there a more optimized way of doing this? This isn’t case sensitive and something like <code>doggen</code> would not return a result for <code>dog</code>. I do not need to stream anything with a StreamReader or StreamWriter and only ACSII text (“abcdefg”, not “82&amp;:!:’ehebeodu”) is being processed. Any answers solving (or helping me solve) this problem would be appreciated. Thanks!</p>
  <p>Edit: New code!</p>
  <pre><code>        public static void FindNumberOfSimilarStrings()
          {
              string[] var = StringOne();
              foreach(string line in StringTwo())
              {
                  foreach(string entry in var)
                  {
                      if (input.IndexOf(line, StringComparison.OrdinalIgnoreCase) &gt;= 0)
                      {
                          Console.WriteLine(line);
                          instances++;
                      }
                  }
              }
              Console.WriteLine(instances);
          }
  </code></pre>