Android String Contain containsIgnoreCase(String str, String query)

Here you can find the source of containsIgnoreCase(String str, String query)

Description

same as String.contains, but ignores case.

Parameter

Parameter Description
str a parameter
query a parameter

Declaration

public static boolean containsIgnoreCase(String str, String query) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   w  w w.  j a v a  2  s . c om
     * same as String.contains, but ignores case.
     * @param str
     * @param query
     * @return
     */
    public static boolean containsIgnoreCase(String str, String query) {
        if (str != null && query != null) {
            int limit = str.length() - query.length() + 1;
            for (int i = 0; i < limit; i++) {
                if (matchesIgnoreCase(str, query, i)) {
                    return true;
                }
            }
        }
        return false;
    }

    private static boolean matchesIgnoreCase(String str, String query,
            int startingAt) {
        int len = query.length();
        for (int i = 0; i < len; i++) {
            if (Character.toUpperCase(query.charAt(i)) != Character
                    .toUpperCase(str.charAt(startingAt + i))) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. contains(String[] str, String searchStr)
  2. contains(String str, List keywords)
  3. cutWords(String src, String contains)
  4. cutWordsAll(String src, String contains)
  5. containsCharRef(String s)
  6. contains(String[] components, String value)
  7. containChinese(String s)
  8. contains(final String str, final char ch)
  9. contains(final String s1, final String s2)