is there a easy way to strip a string of all letters and only allow numbers?
Stripping everything except numbers from string?Solved
many ways: https://stackoverflow.com/questions/3624332/how-do-you-remove-all-the-alphabetic-characters-from-a-string
Regex usually, I prefer LINQ
Regex usually, I prefer LINQ
First, what comes to mind
string ToNumbersOnly(string input){
return string.Join(string.Empty, input.ToList().RemoveAll(c => !char.IsNumber(c)));
} 2CHEVSKII
First, what comes to mind
string ToNumbersOnly(string input){ return string.Join(string.Empty, input.ToList().RemoveAll(c => !char.IsNumber(c))); }
yes, but rather IsDigit than isNumber... (exlude e.g. ½)
Depends on what hes trying to achieve since he has not told us about thatUltra
yes, but rather IsDigit than isNumber... (exlude e.g. ½)
Of course, but it's good to know as it can become a "trap" in future :)
It's a trap! 0_o
Mr. Ts3hosting had asked to keep numbers in a string. I think it's pretty clear what he would like to achieve. ½ is not a number and it would raise an exception in conversion/parsing.
Thanks yes im looking for if somone inputs say ajkdsfa/?sd@&^^@%^(jk it fails i want just inputs of 23489573454.
Oh, if you want to only allow number inputs and ignore all others - use TryParse from some number typeTs3hostingThanks yes im looking for if somone inputs say ajkdsfa/?sd@&^^@%^(jk it fails i want just inputs of 23489573454.
so what im geting at is if string = "32?<$%&*38748" return; if string = "478348723494" good string do whatever
I got it working thanks for the help guys.
Locked automatically