• 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: counting characters
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.


  • Follow-Ups:
    • Re: counting characters
      • From: Koen van der Drift <email@hidden>
    • Re: counting characters
      • From: Allan Odgaard <email@hidden>
References: 
 >Re: counting characters (From: Allan Odgaard <email@hidden>)

  • Prev by Date: Re: counting characters
  • Next by Date: Re: 'Class' may not respond to +isKindOfClass
  • Previous by thread: Re: counting characters
  • Next by thread: Re: counting characters
  • Index(es):
    • Date
    • Thread