public static int findSpace ( String haystack , int begin ) { int space = haystack . indexOf ( ' ' , begin ) ; int nbsp = haystack . indexOf ( ' ' , begin ) ; if ( space == - 1 && nbsp == - 1 ) { return - 1 ; } else if ( space >= 0 && nbsp >= 0 ) { return Math . min ( space , nbsp ) ; } else { // eg one is -1, and the other is >= 0 return Math . max ( space , nbsp ) ; } }
return either the first space or the first nbsp