Java String Sub String substr(String src, int nStart, int nLen)

Here you can find the source of substr(String src, int nStart, int nLen)

Description

substr

License

Open Source License

Parameter

Parameter Description
src a parameter
nStart a parameter
nLen a parameter

Declaration

public static String substr(String src, int nStart, int nLen) 

Method Source Code

//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);
    }
}

Related

  1. substr(byte[] i_Value, int i_BeginIndex)
  2. substr(String s, int start, int end)
  3. substr(String s, String sub, boolean before)
  4. substr(String src, int beginIndex, int endIndex)
  5. subStr(String src, int len)
  6. subStr(String src, String split)
  7. substr(String str, int beginIndex, int endIndex)
  8. substr(String str, int iLen)
  9. substr(String str, int index)