Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check to see if the string is a valid number.

Status
Not open for further replies.

hh2424

Programmer
Feb 18, 2003
37
US
Is there a way to check to see if a string a a valid number with out using the Char.IsNumber() method?

thanks,
 
Thanks for responding.

Yes, I have tried regular expressions to try and do that but that will not handle the commas in the string. I could try and remove all commas from the string but I will not know if the comma is put in the correct place of the string.
I've been using the "try-catch" method of checking for number validation but it slowed down the execution time. I was looking of an alternative method to do it.

thanks,
 
Hi,
Take a look here:
string s1="123.45";
double d=Convert.ToDouble(s1); // d=123.45
s1="-123,456.45";
d=Convert.ToDouble(s1); d=-123456.45
So, use Convert.ToDouble(string) in a try-catch bloc and there will be no slow down execution.

-obislavu-
 
"I have tried regular expressions to try and do that but that will not handle the commas in the string."

Sure it will. You just have to use the proper expression.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top