• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Searching for "whole word" in NSString
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Searching for "whole word" in NSString


  • Subject: Re: Searching for "whole word" in NSString
  • From: Douglas Davidson <email@hidden>
  • Date: Tue, 29 Jan 2008 11:20:16 -0800


On Jan 29, 2008, at 11:05 AM, Citizen wrote:

You could get close with generating the characters you expect to find at the word boundaries with:

NSCharacterSet * wordBoundriesCharacterSet = [[NSCharacterSet letterCharacterSet] invertedSet];

You would need to change this accordingly if you did not want numbers to be considered as a word boundary. You could of course create a boundary character set with just whitespace and punctuation marks - it just depends on how you would like the final feature to work.

It's better not to reinvent the wheel for this sort of tokenization. There is API for word-boundary analysis in AppKit (doubleClickAtIndex: et al.), and, starting in Leopard, also in CoreFoundation (CFStringTokenizer), that handles this in a consistent and standards- appropriate fashion.


The current find panel implementation works by searching for the string in question using any appropriate NSString compare options, then taking each result and determining whether it falls on word boundaries. If a given occurrence doesn't have the right word- boundary characteristics, the search continues.

Douglas Davidson

_______________________________________________

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


  • Follow-Ups:
    • Re: Searching for "whole word" in NSString
      • From: John Stiles <email@hidden>
References: 
 >Searching for "whole word" in NSString (From: John Stiles <email@hidden>)
 >Re: Searching for "whole word" in NSString (From: Citizen <email@hidden>)

  • Prev by Date: How do I rotate an image?
  • Next by Date: Re: Searching for "whole word" in NSString
  • Previous by thread: Re: Searching for "whole word" in NSString
  • Next by thread: Re: Searching for "whole word" in NSString
  • Index(es):
    • Date
    • Thread