question: 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 ; }
target:  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".