Here you can find the source of trunc(String txt, int size)
public static String trunc(String txt, int size)
//package com.java2s; //License from project: Open Source License public class Main { public static String trunc(String txt, int size) { if (txt == null) return txt; else if (txt.length() > size) { return txt.substring(0, size - 1); } else {/*from w w w.j a va2 s . c o m*/ return txt; } } }