views:

60

answers:

2

This is what I'm using

[[remaining_string substringFromIndex:k] substringToIndex:1]

Is there a better way?

+3  A: 

See characterAtIndex

NSString *myString = @"Hello, World";
unichar myChar = [myString characterAtIndex:k];

Note that this returns a unichar. You can use substringWithRange (see Henrik's answer) if you want a NSString.

NullUserException
What if you wanted to return an NSString?
awakeFromNib
But beware that this returns a unichar not a NSString
Henrik P. Hessel
Yeah, that's my question.
awakeFromNib
+2  A: 

And if you want a NSString this should work:

string2 = [string1 substringWithRange: NSMakeRange (k, 1)];
Henrik P. Hessel
That doesn't work.
awakeFromNib
sure it does! c'mon lol
Henrik P. Hessel