Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android compare string ignore case

Tags:

string

android

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?

like image 274
Hieu Do Avatar asked Dec 21 '22 03:12

Hieu Do


2 Answers

Please try following code,

if (userName.trim().equalsIgnoreCase(resultString.trim())) 
{     
       return true; 
} 
like image 167
Lucifer Avatar answered Jan 07 '23 01:01

Lucifer


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;
}
like image 40
Ted Hopp Avatar answered Jan 07 '23 01:01

Ted Hopp