Here you can find the source of truncateString(int length, String srcString)
public static String truncateString(int length, String srcString)
//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; } }