• 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: Finding count of a character in a string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding count of a character in a string


  • Subject: Re: Finding count of a character in a string
  • From: Gideon King <email@hidden>
  • Date: Mon, 22 Aug 2005 19:06:56 +1000

You might use NSScanner to accomplish the same thing - at least that way you won't be creating a potentially large array unnecessarily (just an NSScanner). It may well be slightly more efficient too, although it wouldn't surprise me at all if the implementation of componentsSeparatedByString: used an NSScanner internally...

Gideon King
email@hidden

On 22/08/2005, at 6:49 PM, Paul Harvey wrote:

To find out how many of a particular character there was in large string, I used 'componentsSeparatedByString' method of NSArray then used [array count] to find out how many there were.

Is there a better way, or is this a typical route?

NSArray *verses = [NSArray alloc];
verses = [chapterText componentsSeparatedByString:@"\n"];
verseCount = [verses count];

--
Paul Harvey

Lead Programmer
email@hidden

Hiddenfield Software
"Creating useful software for Mac OS X"
www.hiddenfield.com


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Finding count of a character in a string (From: Paul Harvey <email@hidden>)

  • Prev by Date: Finding count of a character in a string
  • Next by Date: NSArrayController selection issue
  • Previous by thread: Finding count of a character in a string
  • Next by thread: Re: Finding count of a character in a string
  • Index(es):
    • Date
    • Thread