How to make a String array case insensitive in Android -
i creating application read nfc tag , text of tag against string array see if there. works if tag case sensitive correct e.g. 'test', not 'test'. have tried various methods haven't worked. please @ code , see best solution me.
here relevant code:
string[] dd; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); dd = getresources().getstringarray(r.array.device_description); } @override protected void onpostexecute(string result) { if (result != null) { if(arrays.aslist(dd).contains(result)) { vibrator v = (vibrator)getsystemservice(context.vibrator_service); v.vibrate(800); //mtext.settext("read content: " + result); intent newintent = new intent(getapplicationcontext(), tabstest.class); bundle bundle1 = new bundle(); bundle1.putstring("key", result); newintent.putextras(bundle1); startactivity(newintent); toast.maketext(getapplicationcontext(), "nfc tag written successfully!", toast.length_short).show(); } else{ toast.maketext(getapplicationcontext(), result + " not in device description!", toast.length_short).show(); } } }
simple array search can it:
public static boolean doesarraycontain(string[] array, string text) { (string element : array) if(element != null && element.equalsignorecase(text)) { return true; } } return false; }
and can call this:
doescontain(dd, result);
Comments
Post a Comment