[RESOLVED] Converting a string to a number

I want to convert a string to a number.
But some strings have a normal char in it like:    543p  
How can delete all chars, instead of all chars that are normal in a decimal ?

Jelmer850i

How can delete all chars, instead of all chars that are normal in a decimal ?

You can filter out special characters and other alphabets using Int.TryParse method

using System.Linq;
string input = "45234&^&#@$^*367213p";
int number = 0;
input = string.Join("", input.ToCharArray().Where(a => Int32.TryParse(a.ToString(), out number)));

1 thoughts on "[RESOLVED] Converting a string to a number"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>