List of utility methods to do String Truncate
String | truncate(String str, int max) Ensure that the given string is no more than 'max' characters long. return (str.length() > max) ? str.substring(0, max) : str;
|
String | truncate(String str, int max) truncate if (str.length() <= max) { return str; return str.substring(0, max); |
String | truncate(String str, int maxLen) truncates a string regardless of its length. if (str == null || str.length() < maxLen) return str; if (maxLen < 0) return ""; return str.substring(0, maxLen); |
String | truncate(String str, int maxSize) Truncate a string to a max size. if (str == null) { return null; if (str.length() <= maxSize) { return str; return str.substring(0, maxSize); |
String | truncate(String str, int maxSize) truncate if (str != null && maxSize >= 0 && str.length() > maxSize) { return str.substring(0, maxSize); } else { return str; |
String | truncate(String str, int n) Truncates a string and appends an ellipsis. return str.length() < n ? str : (str.substring(0, n) + "..."); |
String | truncate(String str, int size, boolean useEllipsis) Truncate a string to a certain number of characters. String result = str; if (str != null && str.length() > size) { result = str.substring(0, size); if (useEllipsis) { result += "..."; return result; ... |
String | truncate(String str, int start, int end) Returns the string truncated from the start index to end index. if (isNullOrEmpty(str)) { throw new IllegalArgumentException("Invalid String!, str: " + str); if (start < 0 || start > end || end > str.length()) { throw new StringIndexOutOfBoundsException("Invalid Index!, start: " + start + ", endIndex:" + end); StringBuilder sBuilder = new StringBuilder(str); sBuilder.delete(start, end); ... |
String | truncate(String str, String prefix, String suffix) truncate if (str.startsWith(prefix) && str.endsWith(suffix)) return str.substring(prefix.length(), str.length() - suffix.length()); return str; |
String | truncate(String string, final int length) truncate if (string.length() > length) { string = string.substring(0, length); return string; |