Re: [Newbie] Extracting a specific character number from a string
Re: [Newbie] Extracting a specific character number from a string
- Subject: Re: [Newbie] Extracting a specific character number from a string
- From: "Kyle Sluder" <email@hidden>
- Date: Wed, 6 Aug 2008 18:33:06 -0400
On Wed, Aug 6, 2008 at 6:23 PM, Phil Faber <email@hidden> wrote:
> NSLog(@"Character %i of %@ is %@",i,pass1,[pass1 substringWithRange:1,2]);
You need to pass an NSRange struct to -[NSString substringWithRange:].
You can make one using the NSMakeRange() function. If you didn't
know that function existed, you could always have just created one
manually:
NSRange range;
range.location = 1;
range.length = 1;
Also, be careful with NSString character-related functions, because
you get into very thorny issues with respect to "byte" versus
"character" versus "unichar" versus "Unicode code point". String
slicing is not for the faint of heart (or for those unfamiliar with
surrogate pairs).
--Kyle Sluder
_______________________________________________
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:
This email sent to email@hidden