isNumber method
Is the string a number?
st
The string.
Returns true
, if the input string is a number.
Implementation
bool isNumber(String st) {
if (st[0] == _minusSign && st.length == 1) {
return false;
}
if (st[0] == "+" && st.length == 1) {
return false;
}
if (st[0] == _decimalSeparator && (st.length == 1 || !isDigit(st[1]))) {
return false;
}
if (st[0] == 'e' || st[0] == 'E') {
return false;
}
for (int i = 0; i < st.length; i++) {
String ch = st[i];
if (!isDigit(ch) &&
ch != _minusSign &&
ch != _decimalSeparator &&
ch != 'e' &&
ch != 'E' &&
ch != "+") {
return false;
}
}
return true;
}