Last active
January 2, 2016 00:29
-
-
Save brazilnut2000/8223589 to your computer and use it in GitHub Desktop.
C#: Determine whether a string is numeric
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool isNumeric(string val, System.Globalization.NumberStyles NumberStyle) | |
{ | |
Double result; | |
return Double.TryParse(val, NumberStyle, | |
System.Globalization.CultureInfo.CurrentCulture, out result); | |
} | |
/* | |
USAGE: | |
static void Main(string[] args) | |
{ | |
var testThis = "N/A"; | |
// or | |
var testThis = "1234.234"; | |
if (isNumeric(testThis, NumberStyles.Any)) | |
{ | |
Console.WriteLine("I am numeric! {0}", testThis); | |
} | |
Console.ReadKey(); | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment