First create a method
public string RemoveSpecialChars(string str)
{
// Create a string array and add the special characters you want to remove
You can include / exclude more special characters based on your needs
string[] chars = new string[] { ",", ".", "/", "!", "@", "#", "$", "%", "^", "&", "*", "'", "\"", ";","_", "(", ")", ":", "|", "[", "]" };
//Iterate the number of times based on the String array length.

return str;
}
Example:
If you have a string like "$['Suri']"
Now will see how can we use that method
string str = "$['Suri']";
string withoutspecialcharacters = RemoveSpecialChars(str);
//now the output is: Suri


Junaid AhmedPosted May 28, 2018, 10:10 PM EDT
Sourabh Somani, Regex is much slower than this code. This code will take around 45-50 ms while regex will take around 290-300 ms
Sourabh SomaniTOP 100Posted Mar 6, 2018, 8:16 AM EST
Third class way to remove that you can directly use........... Regex.Replace(str, @"[^0-9a-zA-Z]+", "");
Viraj DeshmukhPosted Apr 28, 2015, 7:49 AM EDT
This was very help full for me.Thx
Surendra kumar vermaPosted Sep 30, 2014, 11:03 PM EDT
Very Nice Sir