Android compare string ignore case

12,072

Solution 1

I was panic and didn't try the to print out the result.The problem was my query statement.

   String whereClause = DatabaseHelper.USER_COL + " name =?";

The resultString is always empty unless input is the same as data.

To fix it I follow instruction in this post sqlite LIKE problem in android

   String whereClause = DatabaseHelper.USER_COL + " LIKE ?";
   userName = userName+"%"

Solution 2

Please try following code,

if (userName.trim().equalsIgnoreCase(resultString.trim())) 
{     
       return true; 
} 

Solution 3

Your code should work if the only difference is the case. I suspect you have leading or trailing spaces. Try the following:

if (userName.trim().equalsIgnoreCase(resultString.trim())) {
    return true;
}
Share:
12,072
Author by

Hieu Do

Updated on June 19, 2022

Comments

  • Hieu Do about 1 year

    resultString is the parameter I get from sqlite

    resultString = result.getString(result.getColumnIndex(1));
    

    I want to compare ignore case with user input , following is the code I have use. But it doesn't work.

    For example, in database, I store a username "George" When I login, I have to type exactly "George"."george" doesn't work.

    Here is my code to compare.

    if (userName.equalsIgnoreCase(resultString)) {
        return true;
    }
    

    What might be the problem?