iphone - How to separate the elements from Google vicinity api? -
in ios application want split words google api vicinity, api result shows follows,
"vicinity" : "24/49,tv swamy road east,, tv swamy street, rs puram, coimbatore" "vicinity" : "48, t.v. swamy road west, t.v. swamy road (west), near tasmac, r.s. puram, coimbatore" "vicinity" : "diwan bhadur road, rs puram, coimbatore" "vicinity" : "avinashi road, p.s.g. college stop, avinashi road, near p.s.g. optical centre, peelamedu, coimbatore"
here code try use trim
__block nsstring *lastword = nil; [str enumeratesubstringsinrange:nsmakerange(0, [str length]) options:nsstringenumerationbywords | nsstringenumerationreverse usingblock:^(nsstring *substring, nsrange subrange, nsrange enclosingrange, bool *stop) { lastword = substring; *stop = yes; }];
but results follows
coimbatore coimbatore coimbatore coimbatore
i want show trimmed details follows above result
"tv swamy street, rs puram, coimbatore" "r.s. puram, coimbatore" "rs puram, coimbatore" "peelamedu, coimbatore"
how trim details above?
it's not clear logic cropping strings. if want last 2 components can way
nsarray *results = @[@{@"vicinity" : @"24/49,tv swamy road east,, tv swamy street, rs puram, coimbatore"}, @{@"vicinity" : @"48, t.v. swamy road west, t.v. swamy road (west), near tasmac, r.s. puram, coimbatore"}, @{@"vicinity" : @"diwan bhadur road, rs puram, coimbatore"}, @{@"vicinity" : @"avinashi road, p.s.g. college stop, avinashi road, near p.s.g. optical centre, peelamedu, coimbatore"}]; nsmutablearray *formattedresults = [nsmutablearray array]; (nsdictionary *dict in results) { nsstring *vicinity = dict[@"vicinity"]; nsarray *components = [vicinity componentsseparatedbystring:@","]; nsuinteger length = 2; if ([components count]<length) { break; } nsrange range = nsmakerange([components count]-length, length); nsarray *croppedcomponents = [components subarraywithrange:range]; nsstring *croppedvicinity = [croppedcomponents componentsjoinedbystring:@","]; if (croppedvicinity) { [formattedresults addobject:croppedvicinity]; } } nslog(@"%@",formattedresults);
Comments
Post a Comment