FROM : John Stiles
DATE : Tue Jan 29 20:29:51 2008
Yeah, I've never used NSScanner before.
Is there some sort of sample code which would demonstrate this sort of
usage? It seems like "search for full word" would be a pretty common
usage case.
Citizen wrote:
>
> On 29 Jan 2008, at 18:12, John Stiles wrote:
>
>> I'm trying to find a substring in an NSString. But I want to find
>> whole words (e.g. like in the Find panel when you choose "Full word"
>> from the popup, rather than "Contains" or "Starts With").
>>
>> Unless I'm missing something, it looks like NSString's
>> -rangeOfString:options:range:locale: doesn't have an option for
>> finding whole words.
>>
>> How does the Find panel do it, then? Am I going to have to "roll my
>> own" code for string searching? That sounds error-prone to me; I'd
>> much rather have the OS do it.
>
> 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.
>
> You could then use this character set with an NScanner to search for
> "Full words".
>
> If you have not used an NSScanner before, it is covered in a chapter
> of the Strings Programming Guide for Cocoa:
> <http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/introStrings.html>
>
>
> Of course someone may have a better approach.
>
> Cheers,
> Dave
> ------
> David Kennedy (http://www.zenopolis.com)
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>
DATE : Tue Jan 29 20:29:51 2008
Yeah, I've never used NSScanner before.
Is there some sort of sample code which would demonstrate this sort of
usage? It seems like "search for full word" would be a pretty common
usage case.
Citizen wrote:
>
> On 29 Jan 2008, at 18:12, John Stiles wrote:
>
>> I'm trying to find a substring in an NSString. But I want to find
>> whole words (e.g. like in the Find panel when you choose "Full word"
>> from the popup, rather than "Contains" or "Starts With").
>>
>> Unless I'm missing something, it looks like NSString's
>> -rangeOfString:options:range:locale: doesn't have an option for
>> finding whole words.
>>
>> How does the Find panel do it, then? Am I going to have to "roll my
>> own" code for string searching? That sounds error-prone to me; I'd
>> much rather have the OS do it.
>
> 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.
>
> You could then use this character set with an NScanner to search for
> "Full words".
>
> If you have not used an NSScanner before, it is covered in a chapter
> of the Strings Programming Guide for Cocoa:
> <http://developer.apple.com/documentation/Cocoa/Conceptual/Strings/introStrings.html>
>
>
> Of course someone may have a better approach.
>
> Cheers,
> Dave
> ------
> David Kennedy (http://www.zenopolis.com)
>
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (<email_removed>)
>
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/<email_removed>
>
> This email sent to <email_removed>






Cocoa mail archive

