Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to get array of characters from NSString



This is not a good approach for a number of reasons.

First, Unicode distinguishes between a "code point" (an encoded character), a "code unit" (one 16-bit unichar), and a "grapheme cluster" (what the user thinks of as a character). They're all different. A grapheme cluster may consist of one or more code points, which in turn may each consist of one or two code units. You need to use [NSString rangeOfComposedCharacterAtIndex:] to find the boundaries of an end-user character.

Second, %c means "a single byte in the current legacy encoding". Since characterAtIndex: returns a 16-bit code unit, you want %C, not %c.

Anyone who is considering writing code that looks through the contents of an NSString (as opposed to just treating the whole string as a unit) needs to learn the basics of processing Unicode.

http://www.unicode.org/faq/

Deborah Goldsmith
Apple Inc.
email@hidden

On Aug 8, 2008, at 5:25 AM, Phil Faber wrote:

I'm a newbie myself but this might help you:

As far as I know,

	[ob characterAtIndex:<num>]

(replacing <num> with the character you are after)

..will extract the single character at index <num>.

For example:

NSLog(@"%c",[ob characterAtIndex:i]);

Outputs to the console that character in question.

Phil



On 8 Aug 2008, at 05:27, SridharRao M wrote:

Hi,I want to retrieve characters from NSString Can any one guide me how to
do it.
Ex:
NSString *ob=@"TEST Object";


Now how to retrieve the "Test Object " value into my Char Array.

Regards,
Sri.

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >How to get array of characters from NSString (From: "SridharRao M" <email@hidden>)
 >Re: How to get array of characters from NSString (From: Phil Faber <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.