Java Utililty Methods String Truncate

List of utility methods to do String Truncate

Description

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

Method

StringtruncatePrefixFromPath(String fileName)
truncate Prefix From Path
String pathPrefixComponent[] = fileName.split(":", 2);
if (pathPrefixComponent.length == 1) {
    return pathPrefixComponent[0];
} else {
    return pathPrefixComponent[1];
StringtruncatePunctuation(String authority)
truncate Punctuation
while (authority.startsWith("("))
    authority = authority.substring("(".length()).trim();
while (authority.endsWith("("))
    authority = authority.substring(0, (authority.length() - "(".length())).trim();
while (authority.endsWith(","))
    authority = authority.substring(0, (authority.length() - ",".length())).trim();
while (authority.endsWith(")"))
    authority = authority.substring(0, (authority.length() - ")".length())).trim();
...
StringtruncateSentence(String input, int length)
truncate Sentence
int length2 = length;
while (length2 > 0) {
    char c = (input.charAt(length));
    if (c < 'A' || c > 'z') {
        length2 = 0;
    } else {
        length--;
        length2--;
...
StringtruncateShortMessage(final String message)
truncate Short Message
if (null == message) {
    return "";
} else if (message.length() > MAX_SHORT_MESSAGE_LENGTH) {
    return message.substring(0, MAX_SHORT_MESSAGE_LENGTH);
} else {
    return message;
StringtruncateStr(String str, int maxNumChars)
Truncates a string and adds an ellipse string to the end.
final String ellipse = "...";
if (str == null)
    return "";
if (str.length() >= maxNumChars) {
    StringBuffer newStr = new StringBuffer(maxNumChars);
    newStr.append(str.substring(0, maxNumChars - 1 - ellipse.length()));
    newStr.append(ellipse);
    return newStr.toString();
...
StringtruncateString(final String str, final int iMaxLength)
Truncates a long string, which cannot be shown in full to the user.
String strRet = null;
if (str != null) {
    if (str.length() <= iMaxLength) {
        strRet = str;
    } else if (iMaxLength > 50) {
        final String strAdd = "... (total length of " + str.length() + " characters)";
        strRet = str.substring(0, iMaxLength - strAdd.length()) + strAdd;
    } else if (iMaxLength > 3) {
...
StringtruncateString(int length, String srcString)
truncate String
return srcString.length() < length ? srcString
        : srcString.substring(0, length - 10) + "..."
                + srcString.substring(srcString.length() - 10, srcString.length()) + "[Truncated]";
StringtruncateString(String description, int length)
Will truncated the string to 35 characters in length adding an ellipsis for the last three characters.
String truncated = "";
if (description.length() > length) {
    truncated = description.substring(0, length - 3);
    truncated = truncated + "...";
} else {
    truncated = description;
return truncated;
...
StringtruncateString(String errCode, int length, boolean isRight)
truncate String
if (!isEmpty(errCode)) {
    if (length >= errCode.length()) {
        return errCode;
    } else {
        String subString = "";
        if (isRight) {
            subString = errCode.substring(0, length);
            return subString;
...
StringtruncateString(String inStr, int maxValue)
truncate String
if (inStr == null)
    return null;
int endIndex = inStr.length();
if (inStr.length() > maxValue) {
    endIndex = maxValue - 3;
String outStr = inStr.substring(0, endIndex);
if (inStr.length() > maxValue)
...