java - How to Determine if a String starts with exact number of zeros? -
how can know if string starts {n} number of leading zeros? example below, conditions return true real intention check if string starts 2 zeros.
string str = "00063350449370" if (str.startswith("00")) { // true ... }
you can like:
if ( str.startswith("00") && ! str.startswith("000") ) { // .. }
this make sure string starts "00", not longer string of zeros.
Comments
Post a Comment