class Stuff { /** * "Cleans up" a string by removing all leading and trailing characters * that are not letters. * @param aString the string to be cleaned up * @return the cleaned up version of parameter aString, or a null * pointer if the string contains no letters at all */ public static String cleanUp(String aString) { int pos = aString.length() - 1 ; // start at position of last char // while current char is not a letter while ( ! Character.isLetter(aString.charAt(pos)) ) { pos-- ; // move to previous char if (pos == -1) // if string had no letters... return null ; // ...return null reference } // loop postcondition: pos is position of last letter in aString // remove nonletters from end of aString aString = aString.substring(0, pos+1) ; pos = 0 ; // start at position of first character while ( ! Character.isLetter(aString.charAt(pos)) ) { pos++ ; // move to next char } // loop postcondition: pos is position of first letter in aString // remove nonletters from start of aString aString = aString.substring(pos) ; return aString ; } }