Here you can find the source of truncateToLength(String inputString, int truncateLength)
Parameter | Description |
---|---|
inputString | The String to be truncated |
truncateLength | The Length of the resulting Truncated String |
public static String truncateToLength(String inputString, int truncateLength)
//package com.java2s; public class Main { /**//from ww w.ja v a 2 s . c o m * Method which returns a truncated version of inputString. * If truncateLength is > String length, then the String is returned unmodified * @param inputString The String to be truncated * @param truncateLength The Length of the resulting Truncated String * @return */ public static String truncateToLength(String inputString, int truncateLength) { try { if (truncateLength > inputString.length() - 1) return inputString; else return inputString.substring(0, truncateLength); } catch (Exception e) { if (inputString == null) return " "; else return inputString; } } }