I have a string. It’s always 3 letters long, and it can be counted on to only contain three integers. Say it looks like this:
NSString * numberString = @"123";
Now, I want to extract those numbers from it. 1, 2 and 3. In any other language I’d just fetch the character for each position and parse it, or even cast it.
However, Objective-C doesn’t seem to have that. I found some other answer recommending that i use the characterAtIndex method, use numberWithChar on that, and then subtract the number “48” from it, leaving even myself scratching my head at the apparent stupidity of it all.
Is there no other, more elegant way to do this?
I tried using substringWithRange, but apparently there’s no method for creating an NSRange, and it’s incompatible with CFRangeMake for some reason.
How about [[numberString substringWithRange:NSMakeRange(0,1)] intValue]?