Use int.Parse to check : Number : Data Types C# Source Code


Custom Search

C# Source Code » Data Types » Number »

 

Use int.Parse to check









    


using System;
using System.Data;


class Class1{
        static void Main(string[] args){
      string IsNotNum = "111west";
      string IsNum = "  +111  ";
      string IsFloat = "  23.11  ";
      string IsExp = "  +23 e+11  ";
      
      Console.WriteLine(IsNumeric(IsNum));    // True
      Console.WriteLine(IsNumeric(IsNotNum));    // False
      Console.WriteLine(IsNumeric(IsFloat));    // False
      Console.WriteLine(IsNumeric(IsExp));    // False
      Console.WriteLine();

        }
    public static bool IsNumeric(string str)
    {
      try
      {
        str = str.Trim();
        int foo = int.Parse(str);
        return (true);
      }
      catch (FormatException e)
      {
        Console.WriteLine("Not a numeric value: {0}", e.ToString());
        return (false);
      }
    }
}

           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Data Types
» Number