//Suppose we have a string
string str = "This is testing @#$%!@#$%^&*()_-+";
str = new string(str.Where(c => Char.IsLetterOrDigit(c) || Char.IsWhiteSpace(c)).ToArray());
//now string is filtered all special characters are removed.
Console.Write(str); // This is testing
如果您有比这更好的解决方案,请分享,谢谢
找到这个解决方案来有效地从字符串中删除特殊字符。