这是从 c# 中的字符串中删除特殊字符的最有效方法

问题描述 投票:0回答:0
//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 

如果您有比这更好的解决方案,请分享,谢谢

找到这个解决方案来有效地从字符串中删除特殊字符。

c# .net string char special-characters
© www.soinside.com 2019 - 2024. All rights reserved.