Pages

Aug 12, 2009

How to find and remove Special Characters from a given string. + C#

Here is the method which can remove all the special characters from a given stirng

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;
}


Thanks
Mukunda

No comments: