Monday 15 February 2010

objective c - Match NSString in NSMutableArray to another NSMutableArray with string and save it in an array -



objective c - Match NSString in NSMutableArray to another NSMutableArray with string and save it in an array -

i getting nearby places using google service. , know have filter places containing these words..

_tabledata = [nsmutablearray arraywithobjects: @"ability", @"academy", @"accolade", @"ace", @"active", @"body", @"burn", @"class", @"club", @"court", @"curve", @"dance", @"david", @"degree", @"fight", @"fit", @"gym", @"health", @"lab", @"leisure", @"muscle", @"perform", @"physique", @"promotion", @"recreation", @"sauna", @"shape", @"spa", @"strength", @"tone", @"training", @"west", @"workout",nil];

i searched ..

nsstring *substring = [nsstring stringwithstring:textfield.text]; substring = [substring stringbyreplacingcharactersinrange:range withstring:string]; [self searchautocompleteentrieswithsubstring:substring];

searchautocompleteentrieswithsubstring

- (void)searchautocompleteentrieswithsubstring//:(nsstring *)substring { [_matchplaces removeallobjects]; // int i=0; // (nsstring *word in datatomatch) // { // if ([_tabledata containsobject:word]) // { // // [_matchplaces addobject: [_tabledata objectatindex:i]]; // } // // i++; // } int i=0; for(nsstring *curstring in _tabledata) { nscomparisonresult result = [curstring compare:[datatomatch objectatindex:i] options:(nscaseinsensitivesearch|nsdiacriticinsensitivesearch) range:nsmakerange(0, [[datatomatch objectatindex:i] length])]; //nslog(@"result %@",result); if (result == nsorderedsame) { [_matchplaces addobject:curstring]; } i++; } [_tv reloaddata]; }

this both ways utilize in searchautocompleteentrieswithsubstring returns 1 value match.. can suggest me why returning 1 value match. or share code matching.

match words this..

or how utilize nspredicate matching string

royal mygym string contains gym(case insensitvie)

you can utilize string methods check if string contains string:

if ([[datatomatch objectatindex:i] rangeofstring:curstring options:nscaseinsensitivesearch].location != nsnotfound) { // datatomatch string contains curstring }

ios8 has nsstring method containsstring simpler.

objective-c string-comparison

No comments:

Post a Comment