繁体   English   中英

我想将表单中的用户输入与查询的数据进行比较。 但我希望它不区分大小写。 我怎么做?

[英]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?

/ * 假设txtOrigin和txtDestination的值与查询变量匹配,则将其与 /

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

请尝试:

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

使用.equalsIgnoreCase()方法,例如:

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

}

尝试这个

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

这将使正则表达式为CASE_INSENSITIVE

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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