Here you can find the source of subString(String src, int startIndex, int endIndex)
Parameter | Description |
---|---|
src | string to be splited |
startIndex | start index |
endIndex | end index |
public static String subString(String src, int startIndex, int endIndex)
//package com.java2s; /*/*ww w . j a va2 s. c om*/ * File: $RCSfile$ * * Copyright (c) 2005 Wincor Nixdorf International GmbH, * Heinz-Nixdorf-Ring 1, 33106 Paderborn, Germany * All Rights Reserved. * * This software is the confidential and proprietary information * of Wincor Nixdorf ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered * into with Wincor Nixdorf. */ public class Main { /** * Find substring start by one string end by another string * * @param src source string to be split * @param start start string * @param end end string * @return string between start and end */ public static String subString(String src, String start, String end) { int iStart = src.indexOf(start); int iEnd = src.indexOf(end); if ((iStart == -1) || (iEnd == -1)) { return null; } iEnd += end.length(); return src.substring(iStart, iEnd + 1); } /** * Find substring start by one string end by index * * @param src source string to be split * @param start start string * @param end end index * @return string between start and end */ public static String subString(String src, String start, int end) { int iStart = src.indexOf(start); if ((iStart == -1) || (end == -1)) { return null; } return src.substring(iStart, end); } /** * Find substring start by one index end by index * * @param src string to be splited * @param startIndex start index * @param endIndex end index * @return string between start and end */ public static String subString(String src, int startIndex, int endIndex) { if ((startIndex == -1) || (endIndex == -1)) { return null; } return src.substring(startIndex, endIndex); } /** * Find substring start by first index and end by length * * @param src source string to be split * @param length end index * @return string between start and end */ public static String subString(String src, int length) { if (src == null) { return ""; } if (src.length() <= length) { return src; } else { return src.substring(0, length); } } }