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

时间:2013-03-28 08:12:54

标签: android

/ * 比较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);
                }

3 个答案:

答案 0 :(得分:5)

请尝试:

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

答案 1 :(得分:1)

使用.equalsIgnoreCase()方法 例如:

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

}

答案 2 :(得分:0)

试试这个

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

这将使正则表达式CASE_INSENSITIVE