static boolean isEvenQuotes ( String string ) { // In principle, we could use the regex given by: // Pattern pEvenQuotes = Pattern.compile("([^\"]*\\\"[^\"]*\\\")*[^\"]*"); // We assume just counting the instances of double quotes is more efficient // but we haven't really tested that assumption. boolean even = true ; for ( int i = 0 ; i < string . length ( ) ; i ++ ) { if ( string . charAt ( i ) == ' ' ) { even = ! even ; } } return even ; }
Determines whether the string contains an even number of double quote characters .