Remove Special characters from string



We can remove special characters from a given string by following method:

public string RemoveSpecialChars(string stringWithSpclChar)
{
    string[] SpclChars = new string[] { ",", ".", "/", "!", "@", "#", "$", "%", "^", "&",
    "*", "'", "\"", ";","_", "(", ")", ":", "|", "[", "]" };
    for (int i = 0; i < SpclChars.Length; i++)
    {
        if (stringWithSpclChar.Contains(SpclChars[i]))
           {
               stringWithSpclChar = stringWithSpclChar.Replace(SpclChars[i], "");
           }
     }
     return stringWithSpclChar;
} 

0 Comment's

Comment Form