RE: counting characters
RE: counting characters
- Subject: RE: counting characters
- From: "Jonathan E. Jackel" <email@hidden>
- Date: Thu, 15 Apr 2004 14:09:21 -0400
>
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.