Replace Special Characters from string using Regex

In this Blog I'll tell you about How to Replace Special Characters Using Regex in C#.
 
If you are having a string with special characters and want's to remove/replace them then you can use regex for that.
 
Use this code:
  1. Regex.Replace(your String, @"[^0-9a-zA-Z]+""")  
This code will remove all of the special characters  but if you doesn't want to remove some of the special character for e.g. comma "," and colon ":" then make changes like this:
  1. Regex.Replace(Your String, @"[^0-9a-zA-Z:,]+""")  
Similarly you can make changes according to your requirement. 
Ebook Download
View all
Learn
View all