Java String Sub String substring(String str, int beginIndex, int len)

Here you can find the source of substring(String str, int beginIndex, int len)

Description

substring

License

Open Source License

Declaration

public static String substring(String str, int beginIndex, int len) 

Method Source Code

//package com.java2s;
/*/* w ww.  ja va2s . co m*/
 * StringHelper.java   2004-3-5
 *
 * ??????: ???????(FTO)???? 2000-2005, ?????????.
 * ????????????(FTO)????????????????????????????????????????
 *
 * Copyright 2000-2005 FTO Software Team, Inc. All Rights Reserved.
 * This software is the proprietary information of FTO Software Team, Inc.
 * Use is subject to license terms.
 *
 * FTO???http://www.free-think.org
 */

public class Main {

    public static String substring(String str, int beginIndex, int len) {
        int endIndex = beginIndex + len;
        endIndex = endIndex > str.length() ? str.length() : endIndex;
        return str.substring(beginIndex, endIndex);
    }

    public static String substring(String str, int beginIndex, String endStr) {
        int endIndex = str.indexOf(endStr, beginIndex);
        if (endIndex < 0) {
            return null;
        }
        return str.substring(beginIndex, endIndex);
    }

    public static String substring(String str, String beginStr, int len) {
        int beginIndex = str.indexOf(beginStr);
        if (beginIndex < 0) {
            return null;
        }
        return substring(str, beginIndex + beginStr.length(), len);
    }

    public static String substring(String str, String beginStr, String endStr) {
        int beginIndex = str.indexOf(beginStr);
        if (beginIndex < 0) {
            return null;
        }
        beginIndex = beginIndex + beginStr.length();
        int endIndex = str.indexOf(endStr, beginIndex);
        if (endIndex < 0) {
            return null;
        }
        return str.substring(beginIndex, endIndex);
    }
}

Related

  1. substring(String str, char pattern)
  2. substring(String str, int beginIndex)
  3. subString(String str, int beginIndex, int endIndex)
  4. substring(String str, int beginIndex, int endIndex)
  5. substring(String str, int beginIndex, int endIndex)
  6. subString(String str, int end)
  7. substring(String str, int index, int length)
  8. subString(String str, int len)
  9. substring(String str, int len)