public static String getAt ( String list , String delimiter , int position , boolean ignoreEmpty , String defaultValue ) { if ( delimiter . length ( ) == 1 ) return getAt ( list , delimiter . charAt ( 0 ) , position , ignoreEmpty , defaultValue ) ; int len = list . length ( ) ; if ( len == 0 ) return defaultValue ; int last = - 1 ; int count = - 1 ; char [ ] del = delimiter . toCharArray ( ) ; char c ; for ( int i = 0 ; i < len ; i ++ ) { c = list . charAt ( i ) ; for ( int y = 0 ; y < del . length ; y ++ ) { if ( c == del [ y ] ) { if ( ignoreEmpty && ( last + 1 ) == i ) { last = i ; break ; } count ++ ; if ( count == position ) { return list . substring ( last + 1 , i ) ; } last = i ; break ; } } } if ( position == count + 1 ) { if ( ! ignoreEmpty || last + 1 < len ) return list . substring ( last + 1 ) ; } return defaultValue ; }
gets a value from list