I'm having a String like
XQ74MNT8244A
i nee to remove all the char
from the string.
so the output will be like
748244
How to do this? Please help me to do this
I'm having a String like
XQ74MNT8244A
i nee to remove all the char
from the string.
so the output will be like
748244
How to do this? Please help me to do this
How about an extension method (and overload) that does this for you:
The overload is so you can retain "-", "$" or "." as well, if you wish (instead of strictly numbers).
Usage:
Two options. Using Linq on .Net 4 (on 3.5 it is similar - it doesn't have that many overloads of all methods):
Or, using a regular expression:
I should add that
IsDigit
and\D
are Unicode-aware, so it accepts quite a few digits besides 0-9, for example"542abc٣٤"
.You can easily adapt them to a check between
0
and9
, or to[^0-9]+
.Using LINQ:
Something like this?