title: How to find the specific text in txt file using c#?
body: <p>I have list and text file and I want:</p>
  
  <ol>
  <li>Find all list items that are also in string (matched words) and store them in list or array</li>
  <li>Replace all the found matched words with "Names"</li>
  <li>Count the matched words</li>
  </ol>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>string[] Names = new string[] { "SNOW","Jhon Snow","ADEMS","RONALDO",
  "AABY", "AADLAND", "ANGE", "GEEN", "KHA", "AN", "ANG", "EE", "GEE", "HA", "HAN", "KHAN", 
  "LA", "LAN", "LAND", "NG", "SA", "SAN", "SANG", "LAN","HAN", "LAN", "SANG", "SANG",
  "Sangeen Khan"};
  
  string Text = "I am Sangeen Khan and i am friend AABY. Jhon is friend of AABY.
  AADLAND is good boy and he never speak lie. AABY is also good. SANGEEN KHAN is my name.";
  
  List&lt;string&gt; matchedWords = Names.Where(Text.Contains).ToList();  
  matchedWords.ForEach(w =&gt; Text = Regex.Replace(Text, "\\b" + w + "\\b", 
  "Names", RegexOptions.IgnoreCase));
  int numMatchedWords = matchedWords.Count;
  
  Console.WriteLine($"Matched Words: {string.Join(",", matchedWords.ToArray())}");
  Console.WriteLine($"Count: {numMatchedWords}");
  Console.WriteLine($"Replaced Text: {Text}");
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <blockquote>
    <p>Matched Words: AABY, AADLAND, ANGE, GEEN, KHA, AN, ANG, EE, GEE, HA,
    HAN, KHAN, LA, LAN, LAND, NG, SA, SAN, SANG, LAN, HAN, LAN, SANG,
    SANG, Sangeen Khan</p>
    
    <p>Replaced Text:I am Sangeen Names and i am friend Names. Jhon is friend
    of Names. Names is good boy and he never speak lie. Names is also
    good. SANGEEN Names is my name.</p>
    
    <p>Count: 25</p>
  </blockquote>
  
  <p><strong>Problems:</strong> the code find the "Matched Words" and Number of  Replacement (Count) incorrect. However, the replacement is corrected after reading <a href="https://stackoverflow.com/questions/3904645/string-compare-c-sharp-whole-word-match">String compare C# - whole word match</a></p>
  
  <p>My desired output would be:</p>
  
  <blockquote>
    <p>Matched Words: Sangeen Khan, AABY, KHAN, AADLAND.</p>
    
    <p>Replaced Text: I am Names and i am friend Names. jhon is friend of
    Names. Names is good   boy and he never speak lie. Names is also good.
    Names KHAN is my name.</p>
    
    <p>Count: 7</p>
  </blockquote>