public static String trim ( String string , int pos ) { int len = string . length ( ) ; int leftPos = pos ; int rightPos = len ; for ( ; rightPos > 0 ; -- rightPos ) { char ch = string . charAt ( rightPos - 1 ) ; if ( ch != ' ' && ch != ' ' && ch != ' ' && ch != ' ' ) { break ; } } for ( ; leftPos < rightPos ; ++ leftPos ) { char ch = string . charAt ( leftPos ) ; if ( ch != ' ' && ch != ' ' && ch != ' ' && ch != ' ' ) { break ; } } if ( rightPos <= leftPos ) { return "" ; } return ( leftPos == 0 && rightPos == string . length ( ) ) ? string : string . substring ( leftPos , rightPos ) ; }
Removes all whitespace characters from the beginning and end of the string starting from the given position .