Java String Sub String substr(String src, int beginIndex, int endIndex)

Here you can find the source of substr(String src, int beginIndex, int endIndex)

Description

substr

License

LGPL

Declaration

public static String substr(String src, int beginIndex, int endIndex) 

Method Source Code

//package com.java2s;

public class Main {

    public static String substr(String src, int beginIndex, int endIndex) {
        String dest = "";
        if (src == null) {
            return dest;
        }//from w w w .jav a2 s  .  co m

        byte[] srcByte = src.getBytes();
        byte[] destByte = null;
        int srclen = srcByte.length;
        if (srclen <= beginIndex || beginIndex >= endIndex) {
            return "";
        }

        if (srclen >= endIndex) {
            destByte = new byte[endIndex - beginIndex];
            System.arraycopy(srcByte, beginIndex, destByte, 0, endIndex - beginIndex);
            dest = new String(destByte);
            return dest;
        } else {
            destByte = new byte[srclen - beginIndex];
            System.arraycopy(srcByte, beginIndex, destByte, 0, srclen - beginIndex);
            dest = new String(destByte);
            return dest;
        }
    }
}

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 len)
  5. substr(String src, int nStart, int nLen)
  6. subStr(String src, String split)
  7. substr(String str, int beginIndex, int endIndex)