Here you can find the source of substring(String str, int start, int end)
Parameter | Description |
---|---|
str | The string. |
start | Starting character position (0 origin) of substring |
end | Ending character + 1 position of substring. |
Works like usual String class substring, but handles problem values for start/end values without throwing exceptions.
public static String substring(String str, int start, int end)
//package com.java2s; /* Please see the license information at the end of this file. */ public class Main { /**/*from w ww.j a v a2s. com*/ * Find substring of a string. * * @param str * The string. * @param start * Starting character position (0 origin) of substring * @param end * Ending character + 1 position of substring. * * @return The substring. Empty string if input is null or the substring * doesn't exist. * * <p> * Works like usual String class substring, but handles problem * values for start/end values without throwing exceptions. * </p> */ public static String substring(String str, int start, int end) { String result = ""; if (str != null) { try { result = str.substring(start, end); } catch (Exception e) { } } return result; } }