You are not Logged in
Would you like to Login or Register

Today is: Wednesday, 07 January, 2009
Check this months hot topics

IsNumeric

.NET is missing an IsNumeric function (for c# users anyway). It's dead simple to write one though:

private bool IsNumeric(string s)
{
    try
    {Int32.Parse(s);}
    catch
    {return false;}
    return true;
}
kick it on DotNetKicks.com del.icio.us digg Mister Wong YahooMyWeb Reddit Furl Spurl blogmarks
Lee Keable Skype
Author : Lee Keable
Published : Wednesday, 26 July, 2006

Comments

Paul Hayman said:

Don't forget Int32.TryParse()

Example usage :

  int someNumber;

  if (!Int32.TryParse(s, out someNumber))

  {

    // Not an int

  }

August 08, 2006 - 8:48 PM

Paul Hayman said:

Another example:

int classificationID = 0;

int.TryParse("123", out classificationID);

August 08, 2006 - 9:16 PM

Add Comment

Enter your comment below and it will be submitted for moderation.

Your Name

Add Tag

Please enter tags for this article, seperated by semi-colon ;

View Tag's by : # articles | # views