title: Replace all Special Characters in a string IN C#
body: <p>I would like to find all special characters in a string and replace with a Hyphen (<strong>-</strong>)</p>
  
  <p>I am using the below code </p>
  
  <pre><code>string content = "foo,bar,(regular expression replace) 123";    
  string pattern = "[^a-zA-Z]"; //regex pattern 
  string result  = System.Text.RegularExpressions.Regex.Replace(content,pattern, "-"); 
  </code></pre>
  
  <h1>OutPut</h1>
  
  <blockquote>
    <p>foo-bar--regular-expression-replace----</p>
  </blockquote>
  
  <p>I am getting multiple occurrence of hyphen (---) in the out put. </p>
  
  <p>I would like to get some thing like this</p>
  
  <blockquote>
    <p>foo-bar-regular-expression-replace</p>
  </blockquote>
  
  <p>How do I achieve this </p>
  
  <p>Any help would be appreciated </p>
  
  <p>Thanks
  Deepu</p>