wffweb/src/main/java/com/webfirmframework/wffweb/util/StringUtil.java
public static int[][] startAndEndIndexesOf(final String inputString,
            final String startingWith, final String endingWith) {
        if (!inputString.contains(startingWith)
                || !inputString.contains(endingWith)) {
            return new int[0][0];
        }

        final int inputStringLength = inputString.length();

        final int endingWithLength = endingWith.length();
        final int maxArrayLength = inputStringLength
                / (startingWith.length() + endingWithLength);

        if (maxArrayLength == 0) {
            return new int[0][0];
        }

        final int[][] maxIndexes = new int[maxArrayLength][0];
        int startSearchFromIndex = 0;
        int count = 0;
        do {
            final int startIndex = inputString.indexOf(startingWith,
                    startSearchFromIndex);

            if (!((startIndex + 1) < inputStringLength)) {
                return new int[0][0];
            }

            final int indexOfEndingWith = inputString.indexOf(endingWith,
                    startIndex + 1);

            if (startIndex < 0 || indexOfEndingWith < 0) {
                break;
            }

            final int endIndex = indexOfEndingWith + endingWithLength - 1;
            startSearchFromIndex = endIndex;
            if ((startIndex > endIndex)) {
                startSearchFromIndex = inputStringLength;
            } else {
                final int[] is = { startIndex, endIndex };
                maxIndexes[count] = is;
                count++;
            }
        } while (startSearchFromIndex < inputStringLength);

        final int[][] indexes = new int[count][0];

        // TODO check later if System.arraycopy is better than small sized
        // arrays.
        System.arraycopy(maxIndexes, 0, indexes, 0, count);

        return indexes;
    }
public static int[][] startAndEndIndexesOf(final String inputString,
            final String startingWith, final String endingWith) {
        if (!inputString.contains(startingWith)
                || !inputString.contains(endingWith)) {
            return new int[0][0];
        }

        final int inputStringLength = inputString.length();

        final int endingWithLength = endingWith.length();
        final int maxArrayLength = inputStringLength
                / (startingWith.length() + endingWithLength);

        if (maxArrayLength == 0) {
            return new int[0][0];
        }

        final int[][] maxIndexes = new int[maxArrayLength][0];
        int startSearchFromIndex = 0;
        int count = 0;
        do {
            final int startIndex = inputString.indexOf(startingWith,
                    startSearchFromIndex);

            if (!((startIndex + 1) < inputStringLength)) {
                return new int[0][0];
            }

            final int indexOfEndingWith = inputString.indexOf(endingWith,
                    startIndex + 1);

            if (startIndex < 0 || indexOfEndingWith < 0) {
                break;
            }

            final int endIndex = indexOfEndingWith + endingWithLength - 1;
            startSearchFromIndex = endIndex;
            if ((startIndex > endIndex)) {
                startSearchFromIndex = inputStringLength;
            } else {
                final int[] is = { startIndex, endIndex };
                maxIndexes[count] = is;
                count++;
            }
        } while (startSearchFromIndex < inputStringLength);

        final int[][] indexes = new int[count][0];

        // TODO check later if System.arraycopy is better than small sized
        // arrays.
        System.arraycopy(maxIndexes, 0, indexes, 0, count);

        return indexes;
    }
public static int [ ] [ ] startAndEndIndexesOf ( final String inputString , final String startingWith , final String endingWith ) { if ( ! inputString . contains ( startingWith ) || ! inputString . contains ( endingWith ) ) { return new int [ 0 ] [ 0 ] ; } final int inputStringLength = inputString . length ( ) ; final int endingWithLength = endingWith . length ( ) ; final int maxArrayLength = inputStringLength / ( startingWith . length ( ) + endingWithLength ) ; if ( maxArrayLength == 0 ) { return new int [ 0 ] [ 0 ] ; } final int [ ] [ ] maxIndexes = new int [ maxArrayLength ] [ 0 ] ; int startSearchFromIndex = 0 ; int count = 0 ; do { final int startIndex = inputString . indexOf ( startingWith , startSearchFromIndex ) ; if ( ! ( ( startIndex + 1 ) < inputStringLength ) ) { return new int [ 0 ] [ 0 ] ; } final int indexOfEndingWith = inputString . indexOf ( endingWith , startIndex + 1 ) ; if ( startIndex < 0 || indexOfEndingWith < 0 ) { break ; } final int endIndex = indexOfEndingWith + endingWithLength - 1 ; startSearchFromIndex = endIndex ; if ( ( startIndex > endIndex ) ) { startSearchFromIndex = inputStringLength ; } else { final int [ ] is = { startIndex , endIndex } ; maxIndexes [ count ] = is ; count ++ ; } } while ( startSearchFromIndex < inputStringLength ) ; final int [ ] [ ] indexes = new int [ count ] [ 0 ] ; // TODO check later if System.arraycopy is better than small sized // arrays. System . arraycopy ( maxIndexes , 0 , indexes , 0 , count ) ; return indexes ; }
gets all start and end indexes as an array of array which start and end
with the given values.<br>
Note:- it will never return null instead it will return an empty array
(having length zero).

<pre>

final int[][] startAndEndIndexesOf = startAndEndIndexesOf(
"121 131 141 151 161 171 181 191 101", "1", "1");

for (final int[] startIndexAndEndIndex : startAndEndIndexesOf) {
System.out.println(startIndexAndEndIndex[0] + " - "
+ startIndexAndEndIndex[1]);
}

the output will be :
<i>
0 - 3
4 - 7
8 - 11
12 - 15
16 - 19
20 - 23
24 - 27
28 - 31
32 - 35
</i>

int[] startIndexAndEndIndex = startAndEndIndexesOf[0]; // 1, 2 etc..
System.out.println(startIndexAndEndIndex[0] + " - "
+ startIndexAndEndIndex[1]);

the output will be : <i>0 - 3</i>
</pre>

@param inputString
the string from which the substrings will be
extracted.
@param startingWith
to match the starting substring
@param endingWith
to match the ending substring
@return the array of substrings which contains strings starting and
ending with the given {@code startingWith} and {@code endingWith}
values. Or returns an empty array (i.e an array having length
zero) if it doesn't contain.
@author WFF
@since 1.0.0
gets all start and end indexes as an array of array which start and end with the given values . <br > Note : - it will never return null instead it will return an empty array ( having length zero ) .