如何在字符串中設置區分大小寫?這是我的代碼下面比較字符串如何設置忽略大小寫在這條線?我的應用程序檢查字符串是否包含字符串中的「LOGIN」接收我如何添加ignorecase敏感所以更緊密的字符串包含「登錄」或「登錄」其啓動應用程序?如何在這一行忽略大小寫敏感?
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);
}
使用本s.equalsIgnoreCase (「login」),其中s是一個字符串。 – karn