条件忽略大写?

时间:2013-09-17 16:28:42

标签: java android

如何使条件忽略大写?我想改变:

  

if( Name.contains (layout.txtName.getText()。toString()))

并忽略大写。

case R.id.Contane:
            if (Name.contains(layout.txtName.getText().toString()))
            {
                AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);

                alert.setTitle("this is the first resulet for the name that you typed");

                alert.setMessage("The contact "+Name+" was found in this phone... yaah");

                alert.setPositiveButton("ok",new DialogInterface.OnClickListener() {

                    @Override

                    public void onClick(DialogInterface dialogInterface, int i)
                    {


                    }

                });
                alert.show();
                Found = true;
                break;

3 个答案:

答案 0 :(得分:2)

String库中有一个名为equalsIgnoreCase()的方法,你可以忽略大写锁定。

你也有方法toLowerCase()将大写锁定转为小写。

答案 1 :(得分:2)

尝试toLowerCase()

if ( Name.toLowerCase().contains ( layout.txtName.getText ().toString ().toLowerCase()))

示例:

if("Abc".toLowerCase().contains("a".toLowerCase()))
    System.out.print("Success");

输出:

Success

答案 2 :(得分:0)

尝试:

if (Name.toLowerCase().contains(layout.txtName.getText().toString().toLowerCase()))

不幸的是,没有containsIgnoreCase方法。

此外,您可能想要偏离主题: