Here you can find the source of left(String str, int len)
Parameter | Description |
---|---|
str | string |
len | length |
public static String left(String str, int len)
//package com.java2s; //License from project: LGPL public class Main { /**/*from www.ja v a 2 s .c o m*/ * Get substring from left * @param str string * @param len length * @return substring from left */ public static String left(String str, int len) { if (!nullOrEmpty(str) && str.length() > len) { return str.substring(0, len); } return str; } public static boolean nullOrEmpty(String s) { return (s == null) ? true : "".equals(s.trim()); } public static String trim(String s) { return emptyIfNull(s).trim(); } public static String emptyIfNull(String s) { return (s == null) ? "" : s; } }