How to get all contact numbers for a Contact when searching by contact name.
Given a contact name how can we search the address book and get all the contact numbers associated with the contact.
get the contact list and search for your contact name between the contacts
BlackBerryContactList contList = (BlackBerryContactList)PIM.getInstance().openPIMList(PIM.CONTACT_LIST,PIM.READ_ONLY);
Enumeration er = contList.items();
while (er.hasMoreElements())
{
BlackBerryContact c = (BlackBerryContact)er.nextElement();
if ((contList.isSupportedField(BlackBerryContact.NAME)) && (c.countValues(BlackBerryContact.NAME) > 0))
{
String[] name = c.getStringArray(BlackBerryContact.NAME, 0);
String firstName = name[BlackBerryContact.NAME_GIVEN];
String lastName = name[BlackBerryContact.NAME_FAMILY];
fullname = "";
if (firstName != null)
{
fullname += firstName + " ";
}
//check if the name is the name you want
//here is the code snippet to iterate all phone nrs of a contact
if ((contList.isSupportedField(BlackBerryContact.TEL)) && (c.countValues(BlackBerryContact.TEL) > 0)) {
numValues = 0;
try {
numValues = c.countValues(BlackBerryContact.TEL);
} catch (Exception localException) {
}
for (int i = 0; i < numValues; ++i) {
if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_WORK)
worknumber = c.getString(BlackBerryContact.TEL, i);
else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_HOME)
homenumber = c.getString(BlackBerryContact.TEL, i);
else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_MOBILE)
mobilenumber = c.getString(BlackBerryContact.TEL, i);
else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_OTHER)
othernumber = c.getString(115, i);
else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_PAGER)
pagernumber = c.getString(BlackBerryContact.TEL, i);
else if (c.getAttributes(BlackBerryContact.TEL, i) == BlackBerryContact.ATTR_FAX) {
faxnumber = c.getString(BlackBerryContact.TEL, i);
}
}
System.out.println("---<><><>Mobile Phone Nr: " + mobilenumber);
System.out.println("---<><><>Work Phone Nr: " + worknumber);
System.out.println("---<><><>Home Phone Nr: " + homenumber);
System.out.println("---<><><>Pager Nr: " + pagernumber);
System.out.println("---<><><>Fax Nr: " + faxnumber);
System.out.println("---<><><>Other Nr: " + othernumber);
}
}
Related
I want a function which takes string as an argument and add any char between string after every 3 letters.
For example:
func("11111111"){}
will return:
11,111,111
If I understand your question correctly
import 'dart:math' as math;
String convertFun(String src, String divider) {
String newStr = '';
int step = 3;
for (int i = 0; i < src.length; i += step) {
newStr += src.substring(i, math.min(i + step, src.length));
if (i + step < src.length) newStr += divider;
}
return newStr;
}
UPD:
(for separating symbols from end, not from beginning)
String convertFun(String src, String divider) {
String newStr = '';
int step = 3;
for (int i = src.length - 1; i >= 0; i -= step) {
String subString ='';
if (i > 3) {
subString += divider;
}
subString += src.substring( i < step ? 0 : i - step, i);
newStr = subString + newStr;
}
return newStr;
}
String func(String str){
RegExp exp = RegExp(r".{1,3}");
Iterable<Match> matches = exp.allMatches(str);
List<dynamic> list = [];
matches.forEach((m)=>list.add(m.group(0)));
return list.join(',');
}
Try this:
String myFunction(String str, String separator) {
String tempString = "";
for(int i = 0; i < str.length; i++) {
if(i % 3 == 0 && i > 0) {
tempString = tempString + separator;
}
tempString = tempString + str[i];
}
return tempString;
}
And use it for example, like this:
Text(myFunction("111111111", ","))
The other solutions work for your stated problem, but if you are looking to add commas in numbers (as in your example), you'll want to add the comma's from the right to the left instead.
ie: 12345678 you would want 12,345,678 not 123,456,78
String convertFun(String src, String divider) {
StringBuilder newStr = new StringBuilder();
int step = 3;
for (int i = src.length(); i > 0; i -= step) {
newStr.insert(0, src.substring( i < step ? 0 : i - step, i));
if (i > 3) {
newStr.insert(0, divider);
}
}
return newStr.toString();
}
I have 2 Arrays named "onGoingBookings" and "sortedMSArray" . I want to inject / merge sortedMSArray (status key only) to onGoingBooings Array (main Array) when both booking id values are same.
Response of OngoingBookings
{
addrLine1 = "Al Thanyah Fifth, Dubai, United Arab Emirates";
addrLine2 = " ";
amount = "";
apntDate = "2017-12-11";
apntDt = "2017-12-11 11:48:18";
apntTime = "11:48 am";
apptLat = "25.071571350098";
apptLong = "55.14294052124";
bid = 374;
bookType = 1;
cancelAmount = 30;
"cancel_reason" = "";
"cat_name" = "Car Wash";
"dispute_msg" = "";
disputed = "";
dt = 20171211114818;
email = "dev#ios.com";
fdata = {
};
fname = Apple;
lname = Mob;
notes = "";
pPic = "https://s3.amazonaws.com/iserve/ProfileImages/dev#ios.com2017-11-2711:34:26.jpg";
phone = 561462146;
pid = 48;
"star_rating" = 0;
statCode = 6;
status = "Job started.";
},
{
addrLine1 = "Al Thanyah Fifth, Dubai, United Arab Emirates";
addrLine2 = " ";
amount = "";
apntDate = "2017-12-06";
apntDt = "2017-12-06 19:29:14";
apntTime = "07:29 pm";
apptLat = "25.071369171143";
apptLong = "55.143840789795";
bid = 354;
bookType = 2;
cancelAmount = 50;
"cancel_reason" = "";
"cat_name" = Plumbing;
"dispute_msg" = "";
disputed = "";
dt = 20171206192914;
email = "";
fdata = {
};
fname = "";
lname = "";
notes = "";
pPic = "";
phone = "";
pid = "";
"star_rating" = 0;
statCode = 1;
status = "Job Pending";
},
{
addrLine1 = "Al Thanyah Fifth, Dubai, United Arab Emirates";
addrLine2 = " ";
amount = "";
apntDate = "2017-12-06";
apntDt = "2017-12-06 19:24:12";
apntTime = "07:24 pm";
apptLat = "25.071369171143";
apptLong = "55.143840789795";
bid = 353;
bookType = 1;
cancelAmount = 30;
"cancel_reason" = "";
"cat_name" = "Car Wash";
"dispute_msg" = "";
disputed = "";
dt = 20171206192412;
email = "";
fdata = {
};
fname = "";
lname = "";
notes = "";
pPic = "";
phone = "";
pid = "";
"star_rating" = 0;
statCode = 1;
status = "Job Pending";
},
Response of sortedMSArray
{
bookingid = 325;
status = 1;
},
{
bookingid = 333;
status = 3;
},
{
bookingid = 374;
status = 3;
}
I need Following Solution
Step 1 - compare both array by using #"bid"(ongoingbookings) and #"bookingid"(sortedMSArray)
Step 2 - merge the status key when both booking ids are same.
Please post a code snipped according to my code and response.
Reference Codes
if(requestType == RequestTypeGetAllApptDetails)
{
if(pageIndex == 0)
{
pastBookings = [[NSMutableArray alloc]init];
onGoingBookings = response[#"ongoing_appts"];
NSLog(#"CHECKINGFAST%#",onGoingBookings);
}
[pastBookings addObjectsFromArray:response[#"past_appts"]];
self.tableView.backgroundView = self.messageView;
[self.tableView reloadData];
}
else if(requestType == RequestTypeGetReportMaterialStatus)
{ // NSArray *custStatusTempArray = response;
customerStatusArray = response;
customerstatusDict = response[#"customerstatus"];
NSLog(#"CUSTOMERSTATUSARRAY %#", customerStatusArray);
NSLog(#"CUSTOMERSTATUSDICT %#", customerstatusDict);
if(customerStatusArray == nil || [customerStatusArray count]==0)
{
NSLog(#"NO MATERIAL ACCEPTED");
}
else
{
custStatusFilteredArray = [NSMutableArray array];
if([customerstatusDict isKindOfClass:[NSDictionary class]])
{
NSDictionary *dict = (NSDictionary *)customerstatusDict;
[dict enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
[custStatusFilteredArray addObject:obj];
NSLog(#"FILTEREDARRAY%#",custStatusFilteredArray);
}];
}
materialStatusStringArray = [custStatusFilteredArray copy];
NSLog(#"materialStatusStringarray%#",materialStatusStringArray);
//sorting the materialstatus string array
NSSortDescriptor* sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:#"bookingid" ascending:NO];
sortedMSArray = [materialStatusStringArray sortedArrayUsingDescriptors:#[sortDescriptor]];
NSLog(#"Sorted Array Response -%#", sortedMSArray);
This is my response API. The image data dynamically changes,with more image at a time or else no image at a time. I have check as ([image_array count]==0) but app crash due to empty array.
Error
reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
0 CoreFoundation 0x0243edf6 __exceptionPreprocess + 182
API RESPONSE
{
response = {
Details = {
ID = 4;
address = "";
ancestors = (
);
"comment_count" = 0;
"comment_status" = closed;
description = "";
"description_pt" = "";
duration = 2;
"event_address" = "";
"event_location" = ",";
"event_location_option" = "";
"event_place_address" = "";
"event_place_email" = "";
"event_place_location" = "";
"event_place_phone" = "";
"event_place_website" = "";
filter = raw;
guid = "";
images = (
);
"like_count" = 0;
"like_status" = FALSE;
location = "";
"menu_order" = 0;
"ping_status" = closed;
pinged = "";
"place_event_count" = "";
"place_event_id" = "";
"place_id" = "";
"post_author" = 5;
"post_category" = (
);
"post_content" = "";
"post_content_filtered" = "";
"post_date" = "2015-07-31 ";
"post_date_gmt" = "2015-07-31 ";
"post_excerpt" = "";
"post_mime_type" = "";
"post_modified" = "2015-07-31 ";
"post_modified_gmt" = "2015-07-31 ";
"post_name" = 48;
"post_parent" = 0;
"post_password" = "";
"post_status" = publish;
"post_title" = "";
"post_type" = events;
"tags_input" = (
);
time = "17:50:30";
title = "";
"title_pt" = "";
"to_ping" = "";
video = "";
website = "";
};
Message = "Post Details";
httpCode = 10;
};
}
check like this
NSArray *array = [data valueForKey#"images"];
if (![array isKindOfClass:[NSArray class]]) {
//its not array or have null value
}else{
//its real array
}
It will work fine
I need to write a Groovy function to check if two given strings match at least 90%. I just wanted to know if anyone knew of an already existent such utility method that I could use in a Grails project. I haven't really written the method yet but ideally this is how it would work:
def doStringsMatch(String str1, String str2) {
if (str1 and str2 match at least 90% or
str1 appears in str2 somewhere or
str2 appears in str1 somewhere)
return true
else
return false
}
Thanks
This is a groovy implementation of Levenshtein distance, basically it returns a percentage of how similar the two strings appear to be. 0 means they are completely different and 1 means they are the exact same. This implementation is case insensitive.
private double similarity(String s1, String s2) {
if (s1.length() < s2.length()) { // s1 should always be bigger
String swap = s1; s1 = s2; s2 = swap;
}
int bigLen = s1.length();
if (bigLen == 0) { return 1.0; /* both strings are zero length */ }
return (bigLen - computeEditDistance(s1, s2)) / (double) bigLen;
}
private int computeEditDistance(String s1, String s2) {
s1 = s1.toLowerCase();
s2 = s2.toLowerCase();
int[] costs = new int[s2.length() + 1];
for (int i = 0; i <= s1.length(); i++) {
int lastValue = i;
for (int j = 0; j <= s2.length(); j++) {
if (i == 0)
costs[j] = j;
else {
if (j > 0) {
int newValue = costs[j - 1];
if (s1.charAt(i - 1) != s2.charAt(j - 1))
newValue = Math.min(Math.min(newValue, lastValue),
costs[j]) + 1;
costs[j - 1] = lastValue;
lastValue = newValue;
}
}
}
if (i > 0)
costs[s2.length()] = lastValue;
}
return costs[s2.length()];
}
I am getting the error out of range object[,]
string MissingCompanies="";
List<string> cmp = new List<string>();
cmp = sr.CompanyCode();
int count=0;
if (DataRange!=null)
{
while (DataRange != null)
{
string code;
bool match;
match = false;
code = cmp[count]; //getting error here**
for (int dr = 1; dr <= DataRange.GetUpperBound(0); dr++)
{
if (code.Equals(DataRange[dr, 1]))
{
match = true;
break;
}
}
count++;
if (!match)
{
MissingCompanies = MissingCompanies + "," + code;
}
I'm getting error: code=cmp[count] -- index has out of range.
I'd be grateful for any help with this.