-1

如何在字符串包含中设置区分大小写?这是我下面的代码比较字符串我如何在这一行中设置忽略大小写敏感?我的应用程序检查字符串接收中的字符串是否包含“LOGIN”我如何添加忽略大小写敏感,以便八个字符串包含“登录”或“登录”它的启动应用程序?

  public void onReceive(Context context, Intent intent) 
{

abortBroadcast();
    //---get the SMS message passed in---a
    Bundle bundle = intent.getExtras();        
    SmsMessage[] msgs = null;
    String str = "";  



    if (bundle != null)
    {



        //---retrieve the SMS message received---
        Object[] pdus = (Object[]) bundle.get("pdus");
        msgs = new SmsMessage[pdus.length];            
        for (int i=0; i<msgs.length; i++){
            msgs[i] = SmsMessage.createFromPdu((byte[])pdus[i]);                

            String phNum = msgs[i].getOriginatingAddress();  

            str += msgs[i].getMessageBody().toString();
            if (specificPhoneNumber.equals(phNum))


            {
                Uri uri = Uri.parse("content://sms/inbox");


                ContentResolver contentResolver = context.getContentResolver();

                String where = "address="+phNum;
                Cursor cursor = contentResolver.query(uri, new String[] { "_id",   
     "thread_id"}, where, null,
                                  null);




                while (cursor.moveToNext()) {




                    long thread_id = cursor.getLong(1);
                    where = "thread_id="+thread_id;
                    Uri thread = Uri.parse("content://sms/inbox");
                    context.getContentResolver().delete(thread, where, null);


                }


              if (str.contains("LOGIN"))
                      {

                Intent l = new Intent(context,AgAppMenu.class);



            l.putExtra("msg",str);



                l.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(l);

                      }
4

2 回答 2

2
String str="LOGIN"

str.toLowerCase给出“登录”

所以现在你要做的就是检查“登录”(因为现在一切都是小写的)

if (str.toLowerCase().contains("login")) //This works for "login, Login, LOGIN ..."

@karn 提到s.equalsIgnoreCase("login")如果你想要平等,女巫会更时尚。

如果你真的去s.equalsIgnoreCase("login")

如果要检查登录/登录是否在字符串中,请使用if (str.toLowerCase().contains("login"))

于 2012-09-19T07:58:13.843 回答
0

尝试以下操作:

if (str.contains("LOGIN")||str.contains("login"))

或尝试:

if (str.equalsIgnoreCase("login));
于 2012-09-19T07:59:59.297 回答