Java String Sub String substringCompare(String string, int index, char... characters)

Here you can find the source of substringCompare(String string, int index, char... characters)

Description

Check if the given character sequence is located in the given string at the specified index.

License

Open Source License

Parameter

Parameter Description
string The string to test against
index The location within the string
characters The character sequence to look for.

Return

true if the character sequence was found, otherwise false.

Declaration

private static boolean substringCompare(String string, int index,
        char... characters) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from w ww . j  av a  2s.  c om*/
     * Check if the given character sequence is located in the given
     * string at the specified index. If it is then return true, otherwise false.
     * 
     * @param string The string to test against
     * @param index The location within the string
     * @param characters The character sequence to look for.
     * @return true if the character sequence was found, otherwise false.
     */
    private static boolean substringCompare(String string, int index,
            char... characters) {
        // Is the string long enough?
        if (string.length() <= index + characters.length)
            return false;

        // Do all the characters match?
        for (char character : characters) {
            if (string.charAt(index) != character)
                return false;
            index++;
        }

        return false;
    }
}

Related

  1. subStringByBytes(String str, int toCount, String more)
  2. substringByCodePoint(String inputStr, int codePointStart, int codePointEnd)
  3. substringByMask(String baseString, String baseMask, String subMask)
  4. subStringByte(String str, int toCount, String more)
  5. substringBytes(String value, int byte_len)
  6. substringDelimited(String string, String start, String end, int startingPosition)
  7. substringEL(String str, int index, String defaultValue)
  8. substringEnd(String string, int start, int length)
  9. substringEquals(final String s1, final int fromIndex1, final int toIndex1, final String s2, final int fromIndex2, final int toIndex2)