Rya*_*sen 43
此方法将删除除字母,数字和空格之外的所有内容.它还将删除角色s后面的任何"或".
public static string RemoveSpecialCharacters(string input)
{
Regex r = new Regex("(?:[^a-z0-9 ]|(?<=['\"])s)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
return r.Replace(input, String.Empty);
}
Run Code Online (Sandbox Code Playgroud)
public static string RemoveSpecialCharacters(string input)
{
Regex r = new Regex(
"(?:[^a-zA-Z0-9 ]|(?<=['\"])s)",
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
return r.Replace(input, String.Empty);
}
Run Code Online (Sandbox Code Playgroud)
瑞安的回答是正确的。只需添加A-Z
以及许多人需要它即可。