android - using startsWith and replaceFirst not working for me. -
i print phone contacts in android monitor code below. phone number begins 00 want change 00 + . not working. can tell me wrong please ?
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); contentresolver cr = getcontentresolver(); cursor cur = cr.query(contactscontract.contacts.content_uri, null, null, null, null); if (cur.getcount() > 0) { while (cur.movetonext()) { string id = cur.getstring( cur.getcolumnindex(contactscontract.contacts._id)); string name = cur.getstring(cur.getcolumnindex( contactscontract.contacts.display_name)); if (cur.getint(cur.getcolumnindex( contactscontract.contacts.has_phone_number)) > 0) { cursor pcur = cr.query( contactscontract.commondatakinds.phone.content_uri, null, contactscontract.commondatakinds.phone.contact_id +" = ?", new string[]{id}, null); while (pcur.movetonext()) { string phoneno = pcur.getstring(pcur.getcolumnindex( contactscontract.commondatakinds.phone.number)); if (phoneno.startswith("00")) { system.out.println(phoneno.replacefirst("00", "+")); } system.out.println("name: " + name); system.out.println("phone no: " + phoneno); } pcur.close(); } } }
replacefirst()
returns string
, doesn't mutate object. should perform assignment:
phoneno = phoneno.replacefirst("00", "+")
Comments
Post a Comment