Monday, 15 July 2013

ios - How to detect words within other words in Objective-C -



ios - How to detect words within other words in Objective-C -

so far can observe words within phrases. instance, if user types "pork", item called "cooked pork" returned. however, if user enters "pork", item "pork*" not returned.

this how comparing arrays , catching out words within phrases:

(nsstring *allergicitem in matchagainstarray) { nsstring *lowerstring = [allergicitem lowercasestring]; if ([thelowercellstring rangeofstring:lowerstring].location != nsnotfound) { cell.textlabel.textcolor = [uicolor redcolor]; } else { cell.textlabel.textcolor = [uicolor blackcolor]; } }

my question how can prepare observe word if has little extension " * " in word " pork* ".

ok in simple words want:

if 1 array has word "pork" in it

and array has work "pork*"

i want word "pork*" detected , returned.

my code not returning "pork*", hence why i'm asking question.

if there needs more clarification allow me know.

update:

i have 2 table views populated 2 separate arrays. 1 array populating table view filled ingredients undesirable user, , array populating table view filled ingredients of nutrient item. if 1 of ingredients of nutrient item is same 1 of undesirable items, marked red.

so if nutrient has next ingredients:

water salt chicken*

and user has populated "undesirable ingredient" table view so:

peanuts chicken gluten

when ingredients table view gets displayed, "chicken*" object should marked red.

update 2:

code proving point (which of can test): nsmutablearray *bading = [[nsmutablearray alloc] init]; nsmutablearray *totaling = [[nsmutablearray alloc] init];

[bading addobject:@"chicken"]; [bading addobject:@"gluten"]; [totaling addobject:@"chicken*"]; [totaling addobject:@"water"]; (nsstring *baditem in bading) { nsstring *lowerbadstring= [baditem lowercasestring]; nsstring *totalstring = [totaling objectatindex:0]; nsstring *totallowerstring = [totalstring lowercasestring]; if ([totallowerstring rangeofstring:lowerbadstring].location != nsnotfound) { nslog(@"here object: %@", baditem); } else { nslog(@"we didn't find it"); } }

make list this:

" cooked pork " " roast beef " " candied yams " " porkupine "

(note leading/trailing blanks.)

then utilize " pork " search above list. " cooked pork " match, " porkupine " not.

ios objective-c

No comments:

Post a Comment