On Aug 6, 2008, at 5:23 PM, Phil Faber wrote:

I'm trying to learn more about string manipulation and want to be able to extract a single character from a string. I think I need to use subStringWithRange (exacting from and to the same character location) but I'm not sure and I'm also unsure how to code it.

Basically I'm after the equivalent of the old-fashioned BASIC command MID$ [ i.e. MID$("This is the sentence to check",4,1) to get character 4. ]

The following code works fine except for the..

NSLog(@"Character %i of %@ is %@",i,pass1,[pass1 substringWithRange: 1,2]);

The parameter to substringWithRange is a NSRange. So, you'll need to pass in something like:

NSMakeRange(1, 1)

Note also the second param to NSMakeRange is actually a length value and not an index.

...line simply because I don't know how to code that line. I think it's something to do with how to set the range that I'm getting wrong.

Can anyone please advise what than line is supposed to be to pull out the correct character?

But that is all overkill if you want to extract individual characters from a string. See NSString's characterAtIndex: API.

___________________________________________________________
Ricky A. Sharp         mailto:[EMAIL PROTECTED]
Instant Interactive(tm)   http://www.instantinteractive.com
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to