Re: Approaches for this Matching Problem?
Re: Approaches for this Matching Problem?
- Subject: Re: Approaches for this Matching Problem?
- From: Ken Thomases <email@hidden>
- Date: Mon, 22 Jun 2009 12:52:24 -0500
On Jun 22, 2009, at 3:10 AM, Steve Cronin wrote:
So I've been pondering and testing...
1) Why would I have to bust up/loop on thePhrase?
BUT in my case I don't care where, what word or how often - I just
want to know IF a tag occurs in thePhrase!!
Then you shouldn't refer to "words". If you just care if any of a set
of strings appear in a given string, that's a different question.
If one of your tags is "ham", do you want it to match a phrase
containing "shame"?
- (BOOL) containsTag:(NSString *)thePhrase {
BOOL tagFound = NO;
NSString *tag;
NSEnumerator *tagEnum = [tags objectEnumerator]; //tags is an
NSSet instance variable built from Core Data
while ((tag=[tagEnum nextObject])!=nil) {
if ([thePhrase rangeOfString:tag
options:NSCaseInsensitiveSearch].location!=NSNotFound) {
tagFound = YES; break;
}
}
return tagFound;
}
If you can target Leopard or later, you can simplify this even more by
using "for (NSString* tag in tags) ...". It's more efficient, too.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden