C# Remove special characters

后端 未结 7 2471
孤街浪徒
孤街浪徒 2021-02-07 08:08

I want to remove all special characters from a string. Allowed characters are A-Z (uppercase or lowercase), numbers (0-9), underscore (_), white space ( ), pecentage(%) or the d

7条回答
  •  萌比男神i
    2021-02-07 08:57

    private string RemoveReservedCharacters(string strValue)
    {
        char[] ReservedChars = {'/', ':','*','?','"', '<', '>', '|'};
    
        foreach (char strChar in ReservedChars)
        {
            strValue = strValue.Replace(strChar.ToString(), "");
        }
        return strValue;
    }
    

提交回复
热议问题