Possible Duplicate:
how to check if given c++ string or char* contains only digits?
Im trying to say that
if(string.at(i) != 0-9){
b= true;
}
Is there a way to say this without typing value != 0 && value != 1 ...etc? Also if this exists and is possible, and its different in java I also would find that helpful.
Thanks you guys are always helpful.
C++:
#include <cctype>
using namespace std;
...
if (!isdigit(str[i]))
// or
if (str[i] < '0' || str[i] > '9')
Java:
if (!Character.isDigit(str.charAt(i)))
Say string[i] < 0 || string[i] > 9
.
Make sure you actually mean 0
(the value), and not '0'
(the character for the numeral for zero). In the latter case (as you suggest in the comment), you want string[i] < '0' || string[i] > '9'
. (The numerals are guaranteed to be contiguous and ordered in any text encoding, so this works on any platform.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With