I\'m completely incapable of regular expressions, and so I need some help with a problem that I think would best be solved by using regular expressions.
I have list
Depending on your definition of "special character", I think "[^a-zA-Z0-9]" would probably do the trick. That would find anything that is not a small letter, a capital letter, or a digit.
If you don't want to use Regex then another option is to use
char.IsLetterOrDigit
You can use this to loop through each char of the string and only return if true.
public static string Letters(this string input)
{
return string.Concat(input.Where(x => char.IsLetter(x) && !char.IsSymbol(x) && !char.IsWhiteSpace(x)));
}
For my purposes I wanted all English ASCII chars, so this worked.
html = Regex.Replace(html, "[^\x00-\x80]+", "")
[^a-zA-Z0-9]
is a character class matches any non-alphanumeric characters.
Alternatively, [^\w\d]
does the same thing.
Usage:
string regExp = "[^\w\d]";
string tmp = Regex.Replace(n, regExp, "");
This should do it:
[^a-zA-Z0-9]
Basically it matches all non-alphanumeric characters.