Here you can find the source of truncate(String s, int begin, int end)
public static String truncate(String s, int begin, int end)
//package com.java2s; //License from project: Apache License public class Main { public static String truncate(String s, int begin, int end) { if (isNullOrNone(s)) { return ""; }// w w w. j av a2 s. c o m if (begin < 0) { return ""; } if (begin >= end) { return ""; } s = s.trim(); if (begin >= s.length()) { return ""; } if (end >= s.length()) { return s; } else { return s.substring(begin, end); } } public static boolean isNullOrNone(String s) { if (s == null || "".equals(s.trim())) { return true; } return false; } public static boolean isNullOrNone(Object obj) { if (obj == null) { return true; } if (obj instanceof String) { return isNullOrNone((String) obj); } return false; } public static boolean isNullOrNone(String[] ss) { if (ss == null || ss.length == 0) { return true; } for (int i = 0; i < ss.length; i++) { if (ss[i] == null || "".equals(ss[i].trim())) { return true; } } return false; } }