如何比较字符不区分大小写的基本类型大小写、字符、类型、基本

2023-09-04 08:34:42 作者:栀初

我写的code这几行:

I am writing these lines of code:

String name1 = fname.getText().toString();
String name2 = sname.getText().toString();
aru = 0;

count1 = name1.length();
count2 = name2.length();
for (i = 0; i < count1; i++)
{  
    for (j = 0; j < count2; j++)
    { 
        if (name1.charAt(i)==name2.charAt(j))
            aru++;
    }
    if(aru!=0)
        aru++;
}

我想比较两个字符串忽略大小写的字符。简单的 IGNORECASE 将无法工作,那么我该怎么办呢?添加 65 也不能正常工作。帮助!

I want to compare the chars of two string ignoring the case. Simple IgnoreCase won't work then how do i do that? Adding 65 is also not working. help!

推荐答案

您可以使用字符类的Java API中所具有的各种功能,即转换您烧焦为小写两侧即

You can use Character class of java api which have various functions i.e Convert you char to lower case at both sides i.e

Character.toLowerCase(name1.charAt(i))==Character .toLowerCase(name2.charAt(j))

它也有方法,你可以从中验证是上字母或下即

It also has method from which you can verify is it upper letter or lower i.e

Character.isUpperCase('P')