> On Apr 14, 2016, at 9:33 PM, Daryle Walker <dary...@mac.com> wrote:
> 
> I need a version of the method listed in the subject that works on multiple 
> search strings instead of one, stopping at the first & longest match.  Any 
> ideas?

Depends on your requirements…

If performance isn’t critical, just call -rangeOfData: on each search string, 
then pick the match with the minimum location. (If you don’t know whether 
performance will be critical, do it this way anyway and then profile the app to 
see if it’s fast enough.)

If that’s not fast enough, and the data is text, NSRegularExpression might be 
faster. You’ll need to construct a regex of the form “foo|bar|baz”, i.e. the 
search strings separated with “|”. Metachars in the search strings need to be 
escaped. The actual search should be fast, but constructing the regex will have 
some overhead.

If neither of those is good enough, then you may have to crack open some books 
(or search Github) to find a multiple string search algorithm.

—Jens
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to