Here you can find the source of substr(String src, int nStart, int nLen)
Parameter | Description |
---|---|
src | a parameter |
nStart | a parameter |
nLen | a parameter |
public static String substr(String src, int nStart, int nLen)
//package com.java2s; public class Main { /**//from ww w. ja v a 2 s . c om * * * @param src * @param nStart * @param nLen * @return */ public static String substr(String src, int nStart, int nLen) { if (src == null) return null; byte[] bySrc = src.getBytes(); byte[] byRet = new byte[nLen]; int i, j; for (i = nStart, j = 0; i < bySrc.length && j < nLen; i++, j++) byRet[j] = bySrc[i]; return new String(byRet, 0, j); } /** * @param src * @param nStart * @return */ public static String substr(String src, int nStart) { return substr(src, nStart, src.getBytes().length); } }