Here you can find the source of truncateString(String source, String suffix)
public static String truncateString(String source, String suffix)
//package com.java2s; //License from project: Apache License public class Main { /**//from ww w .j av a 2 s.com Returns a new string that is <i>source</i> with <i>charCount</i> number of characters removed from the end. If <i>charCount</i> >= length of <i>source</i> an empty string is returned. */ public static String truncateString(String source, int charCount) { int tNewLength = Math.max(0, source.length() - charCount); return source.substring(0, tNewLength); } /** Returns a new string that is <i>source</i> with <i>suffix</i> removed from the end. If <i>suffix</i> is not at the end of <i>source</i>, <i>source</i> is returned. */ public static String truncateString(String source, String suffix) { return (source.endsWith(suffix)) ? truncateString(source, suffix.length()) : source; } }