Here you can find the source of substring(final String pSource, final String pBeginBoundaryString, final String pEndBoundaryString, final int pOffset)
Parameter | Description |
---|---|
pSource | The source string. |
pBeginBoundaryString | The string that marks the beginning. |
pEndBoundaryString | The string that marks the end. |
pOffset | The index to start searching in the source string. If it is less than 0, the index will be set to 0. |
public static String substring(final String pSource, final String pBeginBoundaryString, final String pEndBoundaryString, final int pOffset)
//package com.java2s; public class Main { /**//from ww w .ja va2s .c o m * Gets the first substring between the given string boundaries. * <p/> * * @param pSource The source string. * @param pBeginBoundaryString The string that marks the beginning. * @param pEndBoundaryString The string that marks the end. * @param pOffset The index to start searching in the source * string. If it is less than 0, the index will be set to 0. * @return the substring demarcated by the given string boundaries or null * if not both string boundaries are found. */ public static String substring(final String pSource, final String pBeginBoundaryString, final String pEndBoundaryString, final int pOffset) { // Check offset int offset = (pOffset < 0) ? 0 : pOffset; // Find the start index int startIndex = pSource.indexOf(pBeginBoundaryString, offset) + pBeginBoundaryString.length(); if (startIndex < 0) { return null; } // Find the end index int endIndex = pSource.indexOf(pEndBoundaryString, startIndex); if (endIndex < 0) { return null; } return pSource.substring(startIndex, endIndex); } }