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

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -