本文介绍了如何比较原始类型中的字符忽略情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这些代码:

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++;
}

我想比较 Character s两个 String 忽略大小写。只需使用 IgnoreCase 即可。添加65 ASCII 值也不起作用。

I want to compare the Characters of two Strings ignoring the case. Simply using IgnoreCase doesn't work. Adding '65' ASCII value doesn't work either. How do I do this?

推荐答案

您可以使用java api的Character类,它们具有各种功能,即将char转换为小写在两边,即

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')

这篇关于如何比较原始类型中的字符忽略情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 10:02