title: C# - How to find and replace every nth character occurrence using C# or regex? Conversion from Javascript to C#
body: <p><em><strong>Find and replace every 3rd character occurrence in a given string and replace it with H</strong></em></p>
  <p>For instance : <em>74Mercedes1980</em> should be <em>74HerHedHs1H80</em></p>
  <p>Can be done in C# or regex.</p>
  <p>I found this Javascript code that does the same thing and would like to convert it into a C# code. Can you please assist ?</p>
  <p>Found <a href="https://stackoverflow.com/questions/51097042/how-to-find-and-replace-every-nth-character-occurrence-using-regex">here</a></p>
  <pre><code>str = str.replace(/((?:[^x]*x){2}[^x]*)x/g, '$1y');
  
  let str = 'I amx nexver axt hoxme on Sxundxaxs';
  let n = 3;
  let ch = 'x';
  
  let regex = new RegExp(&quot;((?:[^&quot; +ch+ &quot;]*&quot; +ch+ &quot;){&quot; + (n-1) + &quot;}[^&quot; +ch+ &quot;]*)&quot; +ch, &quot;g&quot;);
  
  str = str.replace(regex, '$1y');
  
  console.log(str);
  //=&gt; I amx nexver ayt hoxme on Sxundyaxs
  </code></pre>