I want to strip away all letters in a string, which are not numeric. Preferably a solution made with Regular Expressions or something. And in C#. How to do that?
Using Regex:
str = Regex.Replace(str, @"\D+", "");
\D
is the complement of \d
- matches everything that isn't a digit. +
will match one or more of them (it usually works a little better than one by one).
Using Linq (on .Net 4.0):
str = String.Concat(str.Where(Char.IsDigit));
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