protected String extractSubstring(String pszSrc){
  int nBracket=0;
  int i;
  String pszReturn;
  for (i=0; i < pszSrc.length() && (nBracket > 0 || pszSrc.charAt(i) != ','); i++) {
    if (pszSrc.charAt(i) == '(') {
      nBracket++;
    }
 else     if (pszSrc.charAt(i) == ')') {
      nBracket--;
    }
  }
  if (pszSrc.charAt(0) == '(') {
    pszReturn=pszSrc.substring(1,i - 2);
  }
 else {
    pszReturn=pszSrc.substring(0,i);
  }
  return pszReturn;
}

protected String extractSubstring ( String pszSrc ) { int nBracket = 0 ; int i ; String pszReturn ; for ( i = 0 ; i < pszSrc . length ( ) && ( nBracket > 0 || pszSrc . charAt ( i ) != ',' ) ; i ++ ) { if ( pszSrc . charAt ( i ) == '(' ) { nBracket ++ ; } else if ( pszSrc . charAt ( i ) == ')' ) { nBracket -- ; } } if ( pszSrc . charAt ( 0 ) == '(' ) { pszReturn = pszSrc . substring ( 1 , i - 2 ) ; } else { pszReturn = pszSrc . substring ( 0 , i ) ; } return pszReturn ; }
extract a substring terminated by a comma ( or end of string ) . commas in brackets are ignored as terminated with bracket nesting understood gracefully . if the returned string would being and end with a bracket then strip off the brackets . < p > given a string like " ( a , 3 ( b , c ) , d ) , x , y ) " return " a , 3 ( b , c ) , d " . give a string like " 3a , 2c " return " 3a " .
