public static String getFirstSubstring ( final String inputString , final String startingWith , final String endingWith ) { if ( ! inputString . contains ( startingWith ) || ! inputString . contains ( endingWith ) ) { return null ; } final int startIndex = inputString . indexOf ( startingWith ) ; if ( ! ( ( startIndex + 1 ) < inputString . length ( ) ) ) { return null ; } final int endIndex = inputString . indexOf ( endingWith , startIndex + 1 ) + 1 ; if ( startIndex > endIndex || startIndex < 0 || endIndex < 0 ) { return null ; } return inputString . substring ( startIndex , endIndex ) ; }
gets the first substring which starts and ends with the given values .