• 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
Searching for whole words
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Searching for whole words


  • Subject: Searching for whole words
  • From: Manfred Lippert <email@hidden>
  • Date: Thu, 30 May 2002 22:32:54 +0200

Hi,

I have a search panel with a "Whole Words" search option.
For searching "Whole Words" in an NSAttributedString, I am using the
selector "nextWordFromIndex:forward:". I found out that backwards searching
finds the beginning of words, but forward searching always finds the _end_
of a word (and _not_ the beginning of the next word).

My question: Can I rely on this behaviour? Is this somewhere documented?

Here is my code to check if the NSRange range points to a "whole word" in
the NSAttributedString string:

if ([string nextWordFromIndex:(range.location + 1)
forward:NO] == range.location &&
[string nextWordFromIndex:(range.location + range.length - 1)
forward:YES] == range.location + range.length)) {

// Yes, "range" points to a "whole word"

} else {

// No, "range" does not point to a "whole word"

}

As you can see, this is relying on the fact that
nextWordFromIndex:forward:YES always finds the end of a word, and not the
beginning of the next word.

Is this OK? Or are there any better search algorithms for finding whole
words? (TextEdit's search panel has no "Whole Words" option, so I can
compare with its example code.)

Thanks,
Mani
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: NSURL question (not so easy (i think))
  • Next by Date: Getting the lined background image for menus.
  • Previous by thread: Re: NSURL question (Its working! Thanks for the help!)
  • Next by thread: Adding a NSScriptObjectSpecifier to an event
  • Index(es):
    • Date
    • Thread