using System;
using System.Data;
using System.Text.RegularExpressions;
class Class1{
static void Main(string[] args){
string IsNotNum = "111west";
string IsNum = " +111 ";
string IsFloat = " 23.11 ";
string IsExp = " +23 e+11 ";
Console.WriteLine(IsNumericFromTryParse(IsNum)); // True
Console.WriteLine(IsNumericFromTryParse(IsNotNum)); // False
Console.WriteLine(IsNumericFromTryParse(IsFloat)); // True
Console.WriteLine(IsNumericFromTryParse(IsExp)); // False
}
public static bool IsNumericFromTryParse(string str)
{
double result = 0;
return (double.TryParse(str, System.Globalization.NumberStyles.Float, System.Globalization.NumberFormatInfo.CurrentInfo, out result));
}
}
|