search contacts by phone number, filter using a 3 digit prefix -
i want phone numbers in contacts start specific 3 digits, eg "012" when hit button.
i've been working on using following code:
private void buttoncontacts_click(object sender, routedeventargs e) { contacts cons = new contacts(); //identify method runs after asynchronous search completes. cons.searchcompleted += new eventhandler<contactssearcheventargs>(contacts_searchcompleted); //start asynchronous search. cons.searchasync("0109", filterkind.phonenumber, "state string 5"); } void contacts_searchcompleted(object sender, contactssearcheventargs e) { try { //bind results user interface. contactresultsdata.datacontext = e.results; } catch (system.exception) { //no results } if (contactresultsdata.items.any()) { contactresultslabel.text = "results"; } else { contactresultslabel.text = "no results"; } }
but filterkind.phonenumber
works when has @ least last 6 digits matched of phone number.
idea how achieve this?
btw i'm total beginner.
as say, filter of contacts api match if last 6 digits same, can see in documentation, can't using it.
in opinion best way receive contact list , after use linq find contact want.
private void buttonbase_onclick(object sender, routedeventargs e) { var contacts = new contacts(); contacts.searchcompleted += contacts_searchcompleted; contacts.searchasync(null, filterkind.none, null); } void contacts_searchcompleted(object sender, contactssearcheventargs e) { var results = e.results.toarray(); var mycontacts = results.where(c => c.phonenumbers.any(p => p.phonenumber.startswith("66"))).toarray(); }
you can see in last line query find contacts of numbers start 66. can change query want match numbers want.