Re: NSMutableString, NSString ,character for character
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