1

How to make condition ignore capslock? I want to chang the:

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

and make it ignore the caps.

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 Answers3

2

There is a method in the String library called equalsIgnoreCase(), with this you can ignore caps lock.

You also have the method toLowerCase() which turns caps locks to lower case.

Arash Saidi
  • 2,228
  • 20
  • 36
2

Try toLowerCase()

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

Example:

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

Output:

Success
Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71
0

Try:

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

Unfortunately there is no containsIgnoreCase method.

Also, but off-topic you might want to:

Mena
  • 47,782
  • 11
  • 87
  • 106