public static int nextChar(String s,char needle,int startIndex){
  boolean inSingleQuote=false;
  boolean inDoubleQuote=false;
  for (int i=startIndex; i < s.length(); ++i) {
    char c=s.charAt(i);
    if (!inSingleQuote && !inDoubleQuote && c == needle) {
      return i;
    }
    if (!inSingleQuote && c == '"') {
      inDoubleQuote^=true;
    }
 else     if (!inDoubleQuote && c == '\'') {
      inSingleQuote^=true;
    }
  }
  return -1;
}

public static int nextChar ( String s , char needle , int startIndex ) { boolean inSingleQuote = false ; boolean inDoubleQuote = false ; for ( int i = startIndex ; i < s . length ( ) ; ++ i ) { char c = s . charAt ( i ) ; if ( ! inSingleQuote && ! inDoubleQuote && c == needle ) { return i ; } if ( ! inSingleQuote && c == '"' ) { inDoubleQuote ^= true ; } else if ( ! inDoubleQuote && c == '\'' ) { inSingleQuote ^= true ; } } return - 1 ; }
find the next character ' needle ' in the string ' s ' beginning at ' startindex ' . needles in parts surrounded with quotes ( like attribute values ) are ignored .
