How to Remove all the special characters from a Given String
Hi,
Some times we require to remove all the existing special characters in a string. The same we can done using the following code.
public string RemoveSpecialChars(string str)
{
string[] chars = new string[]{",",".","/","!","@","#","$","%","^","&","*","'","\"",";","-","_","(",")",":","|","[","]"};
for(int i = 0; i< chars.Length; i++ )
{
if(str.Contains(chars[i]))
{
str = str.Replace(chars[i],"");
}
}
return str;
}
string newString = RemoveSpecialChars("T!h^e%c!od#e&i's#s;u$b%m|i%t(te)d by M[o:h]i)t@Ja*i}n");
Not a good solution. I prefer regular expressions.