Java Utililty Methods String Shorten

List of utility methods to do String Shorten

Description

The list of methods to do String Shorten are organized into topic(s).

Method

Stringshorten(String msg, int front, String join, int end)
General short string helper.
if (msg.length() <= (front + join.length() + end))
    return msg;
return msg.substring(0, front) + join + msg.substring(msg.length() - end);
Stringshorten(String name, int max)
shorten
int index = name.indexOf(' ');
while (name.length() > max && index != -1) {
    name = name.substring(index + 1);
    index = name.indexOf(' ');
return name;
Stringshorten(String nameForUI, int maxLen)
shorten
if (nameForUI.length() >= maxLen) {
    maxLen -= 5;
    int first = maxLen / 2;
    int last = maxLen / 2 + (maxLen % 2);
    return nameForUI.substring(0, first) + " ... "
            + nameForUI.substring(nameForUI.length() - last, nameForUI.length());
return nameForUI;
...
Stringshorten(String pkg, boolean shorten)
shorten
if (!shorten) {
    return pkg;
String[] parts = pkg.split("\\.");
StringBuilder result = new StringBuilder();
for (int i = 0; i < parts.length - 1; i++) {
    result.append(parts[i].charAt(0));
    result.append(".");
...
Stringshorten(String s)
shorten
if (null == s) {
    return "NULL";
if (s.indexOf("\n") > -1) {
    int lines = s.split("\n").length;
    int length = s.length();
    s = s.replaceAll("\n", "\\n");
    return String.format("%s(...)%s (len: %d, lines: %d)", s.substring(0, 10),
...
Stringshorten(String s)
shorten
return shorten(s, 20);
Stringshorten(String s)
Returns a string representing the original string appended with suffix "..."
return shorten(s, 20);
Stringshorten(String s)
shorten
return shorten(s, 20);
Stringshorten(String s, int len)
Shortens the string "s" to a length of "len" characters.
if (s == null)
    return null;
if (s.length() > len)
    s = s.substring(0, len - 2) + "..";
return s;
Stringshorten(String s, int length)
Shorten a string using elipses (...)
if (s.length() > length) {
    s = s.substring(0, length - 1) + "...";
return s;