public static CharSequence trim ( CharSequence c ) { if ( c . getClass ( ) == AsciiString . class ) { return ( ( AsciiString ) c ) . trim ( ) ; } if ( c instanceof String ) { return ( ( String ) c ) . trim ( ) ; } int start = 0 , last = c . length ( ) - 1 ; int end = last ; while ( start <= end && c . charAt ( start ) <= ' ' ) { start ++ ; } while ( end >= start && c . charAt ( end ) <= ' ' ) { end -- ; } if ( start == 0 && end == last ) { return c ; } return c . subSequence ( start , end ) ; }
Copies this string removing white space characters from the beginning and end of the string and tries not to copy if possible .