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 29, 2018, 2:10 AM
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 SomaniPosted Mar 6, 2018, 1:16 PM
Third class way to remove that you can directly use........... Regex.Replace(str, @"[^0-9a-zA-Z]+", "");
Viraj DeshmukhPosted Apr 28, 2015, 11:49 AM
This was very help full for me.Thx
Surendra kumar vermaPosted Oct 1, 2014, 3:03 AM
Very Nice Sir