Here you can find the source of subString(String s, int startIndex, int count)
Parameter | Description |
---|---|
s | , giver string |
startIndex | a parameter |
count | , max size of substring |
public static String subString(String s, int startIndex, int count)
//package com.java2s; public class Main { /**//from w w w . jav a 2 s. c o m * slice up the given string * @param s , giver string * @param startIndex * @param count , max size of substring * @return substring */ public static String subString(String s, int startIndex, int count) { if (isEmpty(s)) { return ""; } byte[] stringBytes = s.getBytes(); if (startIndex < 0) { startIndex = 0; } if (count > stringBytes.length - startIndex) { count = stringBytes.length - startIndex; } return new String(stringBytes, startIndex, count); } /** * <p> * Checks if a CharSequence is empty ("") or null. * </p> * * <pre> * StringUtil.isEmpty(null) = true * StringUtil.isEmpty("") = true * StringUtil.isEmpty(" ") = false * StringUtil.isEmpty("bob") = false * StringUtil.isEmpty(" bob ") = false * </pre> * * @param cs * @return */ public static boolean isEmpty(final CharSequence cs) { return cs == null || cs.length() == 0; } }