Java String Sub String substringMatch(CharSequence str, int index, CharSequence substring)

Here you can find the source of substringMatch(CharSequence str, int index, CharSequence substring)

Description

Test whether the given string matches the given substring at the given index.

License

Open Source License

Parameter

Parameter Description
str the original string (or StringBuilder)
index the index in the original string to start matching against
substring the substring to match at the given index

Declaration

public static boolean substringMatch(CharSequence str, int index, CharSequence substring) 

Method Source Code

//package com.java2s;

public class Main {
    /**/*from   ww  w .  j a v  a 2 s.  co m*/
     * Test whether the given string matches the given substring
     * at the given index.
     * @param str the original string (or StringBuilder)
     * @param index the index in the original string to start matching against
     * @param substring the substring to match at the given index
     */
    public static boolean substringMatch(CharSequence str, int index, CharSequence substring) {
        for (int j = 0; j < substring.length(); j++) {
            int i = index + j;
            if (i >= str.length() || str.charAt(i) != substring.charAt(j)) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. substringGuarded(String s, int position, int count)
  2. subStringIgnoreCase(String str, String separator, Integer stratNum, Integer endNum)
  3. substringInBetween(String name, String prefix, String delimiter)
  4. substringL(String s, int i, int len)
  5. substringLinesWithTokenOfEOL( String originalString, String stringToBeInserted)
  6. substringMatch(CharSequence str, int index, CharSequence substring)
  7. substringMatches(final String source, final String substring, final boolean checkBoundaries)
  8. substringMore(String s, int maxlen)
  9. subStringNobit(String str, int toCount, String more)