Re: counting characters
Re: counting characters
- Subject: Re: counting characters
- From: Koen van der Drift <email@hidden>
- Date: Thu, 15 Apr 2004 20:22:35 -0400
Thanks everyone for the suggestions and comments.
- Koen.
On Apr 15, 2004, at 2:09 PM, Jonathan E. Jackel wrote:
On 15. Apr 2004, at 17:52, Jonathan E. Jackel wrote:
The most compact code for counting characters that I can come up with
is:
Compact? Then how about:
NSString* str = @"Hello world";
// count number of o's in string
occurrences = std::count(beginof(str), endof(str), 'o');
// count number of letters in string
occurrences = std::count_if(beginof(str), endof(str), is_letter);
Of course, you can put your code in a category on NSString call it the
Cocoa
way:
int occurrences = [theString numberOfOccurrences:searchString];
Jonathan
_______________________________________________
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.