Java String Truncate truncateString(int length, String srcString)

Here you can find the source of truncateString(int length, String srcString)

Description

truncate String

License

Apache License

Declaration

public static String truncateString(int length, String srcString) 

Method Source Code

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

public class Main {
    public static String truncateString(int length, String srcString) {
        return srcString.length() < length ? srcString
                : srcString.substring(0, length - 10) + "..."
                        + srcString.substring(srcString.length() - 10, srcString.length()) + "[Truncated]";
    }//from w ww .ja va2 s  .c om

    public static String substring(String src, String fromToken, String toToken) {
        int from = src.indexOf(fromToken);
        if (from == -1)
            return null;
        from += fromToken.length();
        int to = src.indexOf(toToken, from);
        if (to == -1) {
            return src.substring(from);
        }
        return src.substring(from, to);
    }

    public static int indexOf(String nextLine, char c) {
        int length = nextLine.length();
        for (int i = 0; i < length; i++) {
            if (c == nextLine.charAt(i))
                return i;
        }
        return -1;
    }

    public static int indexOf(String nextLine, char[] chars) {
        int length = nextLine.length();
        for (int i = 0; i < length; i++) {
            for (char c : chars) {
                if (c == nextLine.charAt(i))
                    return i;
            }
        }

        return -1;
    }
}

Related

  1. truncatePunctuation(String authority)
  2. truncateSentence(String input, int length)
  3. truncateShortMessage(final String message)
  4. truncateStr(String str, int maxNumChars)
  5. truncateString(final String str, final int iMaxLength)
  6. truncateString(String description, int length)
  7. truncateString(String errCode, int length, boolean isRight)
  8. truncateString(String inStr, int maxValue)
  9. truncateString(String s)