I've been scratching my head trying to figure out how to use Regex.Replace to take an arbitrary string and return a string that consists of only the alpha-numeric characters of the original string (all white space and punctuation removed).
Any ideas?
var result = Regex.Replace(input, @"[^a-zA-Z0-9]", "");
You could use linq:
string alphanumeric = new String(original.Where(c => Char.IsLetterOrDigit(c)).ToArray());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With