On Fri, Apr 24, 2009 at 9:24 PM, Gerriet M. Denkmann
<gerr...@mdenkmann.de> wrote:
>
> I want to parse a string into words.
> Currently I do:
>
> NSString *theString = ....
> NSUInteger stringLength = [ theString length ];
> NATextView *theTextView = [[NSTextView alloc] initWithFrame:
> NSMakeRect(0,0,99,99) ];
> [ theTextView setString: theString ];
>
> for( NSUInteger t = 0; t < stringLength;)
> {
>        NSRange proposedSelRange = NSMakeRange(t,0);
>        NSRange wordRange = [ theTextView
> selectionRangeForProposedRange: proposedSelRange
>
>    granularity:                                    NSSelectByWord
>                                                ];
>        NSString *word = [ theString substringWithRange: wordRange ];
>        t = NSMaxRange( wordRange );
>
>        //      do something with <word>
> };
>
> [ theTextView release ];
>
> but this looks rather wasteful. Is there a more elegant way?
>
> Please note that there are lots of languages, where words are not separated
> by space or punctuation.

If you can require 10.5, use CFStringTokenizer. It is really great,
and is a lot simpler and less evil than this.

Mike
_______________________________________________

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

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

Reply via email to