1 min read

C# Query from Google

Paul Kinlan

Paul Kinlan

Lead of Chrome DevRel

One of the queries that someone entered in to Google and found my site was:c# test a string to see if it is a number:I suppose there are a couple of ways that this can be done.

If you know the datatype that you want to convert it to [i.e you know the numeric range] you can use the Convert class.Convert.ToInt16 (short), Convert.ToInt32 (int), Convert.ToFloat (floats). etc etc

You could also use a regex along the lines of:

/^[0-9]+$/or/^[\d]+$/

both of the above regex's will check to see if it is a numeric string. (Whole numbers only though).

Anyone who is looking for c# test a string to see if it is a number; I hope you find this usefull.

Stay in the loop.

I'm trialing a newsletter. Join for monthly insights into web dev, Chrome, and the open web.

alternate_email

Get in touch

Open to chat about Chrome or Web development.

Book a consultation