简体   繁体   中英

I want to compare the user input from my form to the queried data. but I want it not to be case sensitive. how do I do that?

/* compares the values of txtOrigin and txtDestination to the query variables assuming it matches /

                if((origin.getText().toString().matches(queryOrigin))
                        && (destination.getText().toString().matches(queryDestination)))
                {
                //proceed to route found layout
                    Intent openRouteFound = new Intent("com.icommute.feu.RouteFound");
                    startActivity(openRouteFound);
                }

            /**compares the values of txtOrigin 
            and txtDestination to the query 
            variables assuming it doesn't match*/
                else
                {
                //proceed to no routes found layout
                    Intent openNoRoute = new Intent("com.icommute.feu.NoRoute");
                    startActivity(openNoRoute);
                }

Please try that:

 if((origin.getText().toString().equalsIgnoreCase(queryOrigin))
      && (destination.getText().toString().equalsIgnoreCase(queryDestination)))
 {
    ...
 }

use .equalsIgnoreCase() method eg:

if((origin.getText().toString().equalsIgnoreCase(queryOrigin))
                    && (destination.getText().toString().equalsIgnoreCase(queryDestination)))
            {

}

Try this

origin.getText().toString().matches("(?i)" + queryOrigin) .

This will make regex CASE_INSENSITIVE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM