title: Counting strings in files and putting the value in different places using c#?
body: <p>I'm trying to count some strings in files in a given location and then put those values in some nodes.
  I've tried the below code</p>
  
  <pre><code>var workingPath=@"D:\Test\MyFiles";
              var files = new List&lt;string&gt;();
              if (Directory.Exists(workingPath))
              {
                  foreach (var f in Directory.GetDirectories(workingPath, "xml",
                                                             SearchOption.AllDirectories))
                  {
                      files.AddRange(Directory.GetFiles(f, "*.xml"));
                  }
              }
  
              foreach (var file in files) {
                  string text = File.ReadAllText(file);
                  int fig_count = Regex.Matches(text, @"fig id=""fig").Count;
                  int tab_count = Regex.Matches(text, @"table-wrap id=""table").Count;
                  int eq_count = Regex.Matches(text, @"disp-formula id=""deqn").Count;
                  File.WriteAllText(file,Regex.Replace(File.ReadAllText(file), @"&lt;fig-count count=""\d+""/&gt;",@"&lt;fig-count count="""+fig_count+@"""/&gt;"));
                  File.WriteAllText(file,Regex.Replace(File.ReadAllText(file), @"&lt;table-count count=""\d+""/&gt;",@"&lt;table-count count="""+tab_count+@"""/&gt;"));
                  File.WriteAllText(file,Regex.Replace(File.ReadAllText(file), @"&lt;eq-count count=""\d+""/&gt;",@"&lt;eq-count count="""+eq_count+@"""/&gt;"));
              }
  </code></pre>
  
  <p>The code works but it is a bit redundant. Can anyone tell me how to make it less redundant?</p>