Remove Special characters from string

Ranjeet_8
Posted by Ranjeet_8 under ASP.NET category on | Points: 40 | Views : 1508

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

Comments or Responses

Login to post response