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;
}
Author Lee Keable

Comments

Paul Hayman said:

Don't forget Int32.TryParse()

Example usage :

  int someNumber;

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

  {

    // Not an int

  }

08/Aug/2006 20:48 PM

Paul Hayman said:

Another example:

int classificationID = 0;

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

08/Aug/2006 21:16 PM

Add Comment

Name
Comment
 

Your comment has been received and will be shown once it passes moderation.