public static String cleanTruncate(String s,int length){
  if (s == null) {
    return s;
  }
  if (length == 0) {
    return "";
  }
  if (length >= s.length()) {
    return s;
  }
  if (Character.isHighSurrogate(s.charAt(length - 1))) {
    length--;
  }
  return s.substring(0,length);
}

public static String cleanTruncate ( String s , int length ) { if ( s == null ) { return s ; } if ( length == 0 ) { return "" ; } if ( length >= s . length ( ) ) { return s ; } if ( Character . isHighSurrogate ( s . charAt ( length - 1 ) ) ) { length -- ; } return s . substring ( 0 , length ) ; }
truncates string to a length less than length . backtracks to throw out high surrogates .
