Determine if a string is numeric: Difference between revisions

Content added Content deleted
(→‎[[mIRC]]: mIRC is the interpreter. MSL is the scripting language.)
Line 55: Line 55:
}
}


Alternative 1 : Check that each character in the string is number
Alternative 1 : Check that each character in the string is number. Note that this will only works for integers.



private static final boolean isNumeric(final String s) {
private static final boolean isNumeric(final String s) {
Line 68: Line 67:
}
}


Alternative 2 : use a regular expression ( a more elegant solution)
Alternative 2 : use a regular expression (a more elegant solution). Also, only for integers.


public static boolean IsNumeric(string inputData) {
public static boolean IsNumeric(string inputData) {
final static Regex isNumber = new Regex(@"^\d+$");
final static Regex isNumber = new Regex(@"^-{0,1}\d+$");
Match m = isNumber.Match(inputData);
Match m = isNumber.Match(inputData);
return m.Success;
return m.Success;