Re: Word count
Re: Word count
- Subject: Re: Word count
- From: j o a r <email@hidden>
- Date: Wed, 9 Jun 2004 08:57:24 +0200
On 2004-06-09, at 08.05, Matt Baker wrote:
>
Anyone know an effiecient way to do a word count on an NSString or
>
(better yet) an NSAttributedString? I'm having trouble getting the
>
spell checker to count the words (always returns 0) and I see I can
>
get an array of the words using NSTextStorage, but that horribly
>
memory-sucking in my opinion. That, and I cannot instantiate a
>
NSTextStorage object (I could get it from an NSTextView, but I'd
>
rather not have to add a text view to just get a word count).
You can do something like this:
int wc = [[myString componentsSeparatedByString: @" "] count];
or
int wc = [[[myAttributedString string] componentsSeparatedByString: @"
"] count];
If it will give you acceptable performance or not depends on how you
use it (how large is the string, how often is it called, et.c.).
j o a r
[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.
References: | |
| >Word count (From: Matt Baker <email@hidden>) |