public static String trimToMaxLength(String s,int maxLength){
  try {
    if (s != null && s.length() > maxLength) {
      return s.substring(0,maxLength);
    }
 else {
      return s;
    }
  }
 catch (  StringIndexOutOfBoundsException e) {
    throw new IllegalArgumentException(format("trimToMaxLength(%s, %d)",s,maxLength));
  }
}

public static String trimToMaxLength ( String s , int maxLength ) { try { if ( s != null && s . length ( ) > maxLength ) { return s . substring ( 0 , maxLength ) ; } else { return s ; } } catch ( StringIndexOutOfBoundsException e ) { throw new IllegalArgumentException ( format ( "trimToMaxLength(%s, %d)" , s , maxLength ) ) ; } }
trim a string if it exceeds a maximum length .
