Java String Truncate truncateString(String errCode, int length, boolean isRight)

Here you can find the source of truncateString(String errCode, int length, boolean isRight)

Description

truncate String

License

Apache License

Declaration

public static String truncateString(String errCode, int length, boolean isRight) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static String truncateString(String errCode, int length, boolean isRight) {
        if (!isEmpty(errCode)) {
            if (length >= errCode.length()) {
                return errCode;
            } else {
                String subString = "";
                if (isRight) {
                    subString = errCode.substring(0, length);
                    return subString;
                } else {
                    subString = errCode.substring(errCode.length() - length, errCode.length());
                    return subString;
                }/*w  w w. ja va 2 s.  com*/
            }
        }
        return errCode;
    }

    public static boolean isEmpty(String str) {
        if (str == null || str.trim().length() == 0) {
            return true;
        }

        return false;
    }
}

Related

  1. truncateShortMessage(final String message)
  2. truncateStr(String str, int maxNumChars)
  3. truncateString(final String str, final int iMaxLength)
  4. truncateString(int length, String srcString)
  5. truncateString(String description, int length)
  6. truncateString(String inStr, int maxValue)
  7. truncateString(String s)
  8. truncateString(String s, int numChars)
  9. truncateString(String source, int prefixLength, int totalLength)