@Test public void testSubstr_01() { assertEquals("01", null, StringUtil.substr(null, 0, 5)); assertEquals("02", "", StringUtil.substr("", 0, -1)); assertEquals("03", "", StringUtil.substr("whatever", 0, -1)); assertEquals("04", "", StringUtil.substr("whatever", 1, 0)); assertEquals("05", "", StringUtil.substr("whatever", 250, 3)); assertEquals("06", "what", StringUtil.substr("whatever", 0, 4)); assertEquals("07", "ever", StringUtil.substr("whatever", -4, 4)); assertEquals("08", "ever", StringUtil.substr("whatever", -4, 250)); assertEquals("09", "", StringUtil.substr("whatever", 200, 250)); assertEquals("10", "eve", StringUtil.substr("whatever", -4, 3)); assertEquals("11", "e", StringUtil.substr("whatever", -4, 1)); assertEquals("12", "e", StringUtil.substr("whatever", 4, 1)); assertEquals("13", "what", StringUtil.substr("whatever", -250, 4)); assertEquals("14", "whatever", StringUtil.substr("whatever", -250, 1000)); }
public static String substr(String string, int from) { if (string == null) { return null; } if (from > string.length()) { return EMPTY; } if (from < 0) { from = Math.max(0, string.length() + from); } return string.substring(from); }
StringUtil { public static String substr(String string, int from) { if (string == null) { return null; } if (from > string.length()) { return EMPTY; } if (from < 0) { from = Math.max(0, string.length() + from); } return string.substring(from); } }
StringUtil { public static String substr(String string, int from) { if (string == null) { return null; } if (from > string.length()) { return EMPTY; } if (from < 0) { from = Math.max(0, string.length() + from); } return string.substring(from); }  }
StringUtil { public static String substr(String string, int from) { if (string == null) { return null; } if (from > string.length()) { return EMPTY; } if (from < 0) { from = Math.max(0, string.length() + from); } return string.substring(from); }  static String substr(String string, int from); static String substr(String string, int from, int length); static String zpad(Object obj, int width, String separator); static String zpad(Object obj, int width); static String lpad(Object obj, int width, String separator); static String pad(Object obj, int width); static String pad(Object obj, int width, char padChar); static String pad(Object obj, int width, char padChar, String separator); static String lpad(Object obj, int width); static String lpad(Object obj, int width, char padChar); static String lpad(Object obj, int width, char padChar, String separator); static String rpad(Object obj, int width, String separator); static String rpad(Object obj, int width); static String rpad(Object obj, int width, char padChar); static String rpad(Object obj, int width, char padChar, String separator); static String substring(String string, int from, int to); static String toString(byte[] bytes); static String lchop(String string, String word); static String rchop(String string, String word); static String[] split(String s, String delim); static String[] split(String s, String delim, int numParts); static String trim(String s, char c); static String ltrim(String s, char c); static String trim(String s, char... chars); static String trim(String s, String chars); static String rtrim(String s, char c); static boolean isTrue(String s); static boolean isTrue(String s, boolean dfault); static String getResourceAsString(String path); static InputStream toInputStream(String s); static InputStream toInputStream(String s, String charset); static String fromInputStream(InputStream is); static String fromInputStream(InputStream is, String charset); static String fromInputStream(InputStream is, String charset, int bufsize); static int toInt(String s); static String emptyIfNull(String str); }
StringUtil { public static String substr(String string, int from) { if (string == null) { return null; } if (from > string.length()) { return EMPTY; } if (from < 0) { from = Math.max(0, string.length() + from); } return string.substring(from); }  static String substr(String string, int from); static String substr(String string, int from, int length); static String zpad(Object obj, int width, String separator); static String zpad(Object obj, int width); static String lpad(Object obj, int width, String separator); static String pad(Object obj, int width); static String pad(Object obj, int width, char padChar); static String pad(Object obj, int width, char padChar, String separator); static String lpad(Object obj, int width); static String lpad(Object obj, int width, char padChar); static String lpad(Object obj, int width, char padChar, String separator); static String rpad(Object obj, int width, String separator); static String rpad(Object obj, int width); static String rpad(Object obj, int width, char padChar); static String rpad(Object obj, int width, char padChar, String separator); static String substring(String string, int from, int to); static String toString(byte[] bytes); static String lchop(String string, String word); static String rchop(String string, String word); static String[] split(String s, String delim); static String[] split(String s, String delim, int numParts); static String trim(String s, char c); static String ltrim(String s, char c); static String trim(String s, char... chars); static String trim(String s, String chars); static String rtrim(String s, char c); static boolean isTrue(String s); static boolean isTrue(String s, boolean dfault); static String getResourceAsString(String path); static InputStream toInputStream(String s); static InputStream toInputStream(String s, String charset); static String fromInputStream(InputStream is); static String fromInputStream(InputStream is, String charset); static String fromInputStream(InputStream is, String charset, int bufsize); static int toInt(String s); static String emptyIfNull(String str); static final String EMPTY; }