• 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: NSMutableString, NSString ,character for character
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableString, NSString ,character for character


  • Subject: Re: NSMutableString, NSString ,character for character
  • From: Ali Ozer <email@hidden>
  • Date: Thu, 12 Jul 2001 19:39:03 -0700

There is indeed characterAtIndex:. Loop from 0 to [string length] - 1.

You can't put characters into an NSArray, as NSArrays hold objects, which characters aren't.

One question is, why do you want the individual characters? Typically people don't need to go into strings too much.

Now for a slightly advanced, performance topic:

Instead of characterAtIndex:, you can also use getCharacters:range: for bulk getting of characters. If you're enumerating all the characters in a potentially huge string and doing something quick with each one, calling getCharacters:range: a few times into a fixed size stack allocated buffer might be quicker than many calls to characterAtIndex: as it will avoid numerous message sends. (If you decide to use the bulk-access method, also see CFStringGetCharacterFromInlineBuffer() in CFString.h.)

Note that if you're strings are small no need for any of this.

Ali



On Thursday, July 12, 2001, at 06:23 , Michel Haver wrote:

Question:

If you try to do something hard like writing your first cocoa application,
some simple C stuff becomes mind boggling in cocoa, so here is my question:

NSString * drawString;

drawString = @"test";

How do I get the characters t e s t in this NSString? Can it be converted to
a NSArray?

Can you write out a NSString or NSMutableString character be character? Is
there by something like characterAtIndex functionality, or must it be coded
by a character loop?

Cheers,

Michel
_______________________________________________
cocoa-dev mailing list
email@hidden
http://www.lists.apple.com/mailman/listinfo/cocoa-dev


References: 
 >NSMutableString, NSString ,character for character (From: Michel Haver <email@hidden>)

  • Prev by Date: Re: alloc, dealloc, retain, release, autorelease etc.
  • Next by Date: contextual menus
  • Previous by thread: NSMutableString, NSString ,character for character
  • Next by thread: Re: NSMutableString, NSString ,character for character
  • Index(es):
    • Date
    • Thread