Here you can find the source of truncString(String in, int len)
Parameter | Description |
---|---|
in | the string that may need tuncating. |
len | the lenght that the string should be truncated to. |
null
if input String is null
.
public static String truncString(String in, int len)
//package com.java2s; //License from project: Apache License public class Main { /**//from w w w . ja v a2 s .com * Simple static method to tuncate Strings to given length. * @param in the string that may need tuncating. * @param len the lenght that the string should be truncated to. * @return a new String containing chars with length <= len or <code>null</code> * if input String is <code>null</code>. */ public static String truncString(String in, int len) { String out = in; if (in != null && len > 0 && in.length() > len) { out = in.substring(0, len); } return out; } }