如何比较字符不区分大小写的基本类型 [英] How to compare character ignoring case in primitive types

查看:130
本文介绍了如何比较字符不区分大小写的基本类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的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') 

这篇关于如何比较字符不区分大小写的基本类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆