簡體   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