• 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: parsing a string into words
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: parsing a string into words


  • Subject: Re: parsing a string into words
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Sat, 25 Apr 2009 16:15:49 +0700


On 25 Apr 2009, at 09:21, Michael Ash <email@hidden> wrote:

On Fri, Apr 24, 2009 at 9:24 PM, Gerriet M. Denkmann <email@hidden> 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.


Thanks a lot. This was exactly what I was looking for.
But without knowing the term "CFStringTokenizer", it is really hard to find.


But this is a general problem:
Cocoa is just the tip of the iceberg, on top of lots of additional C- APIs which are needed to solve the not so common problems.


Would it not be a good idea, if e.g. the documentation for NSString would mention the C-APIs which can be used for functionality which NSString does not offer?
Like CFStringTransform, CFStringTokenizer etc.



Kind regards,

Gerriet.

_______________________________________________

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: parsing a string into words
      • From: Aki Inoue <email@hidden>
  • Prev by Date: Auxiliary background executable without dock icon but with some UI
  • Next by Date: How to set tags for ComboBox cell items?
  • Previous by thread: Re: parsing a string into words
  • Next by thread: Re: parsing a string into words
  • Index(es):
    • Date
    • Thread