Find value at index i and length m .
int value = 0 ; for ( int j = 0 ; j < m ; j ++ ) { int c = str . charAt ( i + j ) - '0' ; if ( c < 0 c > 9 ) { return - 1 ; } value = value * 10 + c ; } return value ; }