Re: Approaches for this Matching Problem?
Re: Approaches for this Matching Problem?
- Subject: Re: Approaches for this Matching Problem?
- From: Steve Cronin <email@hidden>
- Date: Mon, 22 Jun 2009 03:10:55 -0500
Ken & Jerry;
Thanks for the quick response!
So I've been pondering and testing...
1) Why would I have to bust up/loop on thePhrase? This makes me face
Jerry's issue of a universal solution for breaking on words.
Just on general principal what would that solution be?
[thePhrase componentsSeparatedByString:@" "] sure is easy, fast and
effective for most of the folks who are going to pay for indie
software....
But what is the right solution??
Seems like a common enough problem that there should be a well-
defined, easily obtained, well-documented answer....
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!!
thePhrase = 8 words
theTags = 150 words
the code below: 0.001 sec on 2Ghz MacBook -- Yeeoowssah!
-- added benefits beyond spec
-easy code to understand - not prone to error
-Search and Comparison options allow for easily implemented
flexibility - case-sensitivity; anchored, etc..
- (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;
}
Thanks for making life good!
Steve
_______________________________________________
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