Getting Number From Character In NSString
I'm trying to extract an integer from the second character of an NSString but I can't seem to figure out how to get it. Here's what my call currently looks like (doesn't work). Can anyone help me out?
Code:
SupplyCrate *crate = [crateList objectAtIndex:[NSNumber numberWithChar:[missileStatus characterAtIndex:1]]];
From the look of your code you want to do [crateList objectAtIndex:[[missileStatus substringWithRange:NSMakeRange(1, 1)] intValue]]
1. objectAtIndex: takes an int not an object
2. I suspect you don't want to be dealing in actual character values but their English equivalents, numberWithChar: will give you 49 for '1'
1. objectAtIndex: takes an int not an object
2. I suspect you don't want to be dealing in actual character values but their English equivalents, numberWithChar: will give you 49 for '1'
Thanks.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Malloc() Struct with NSString Inside? | Graphic Ace | 3 | 3,866 |
Jan 26, 2010 05:32 PM Last Post: cmiller |
|
| What do you want to see in a Random Number Generator? | Justin Brimm | 16 | 6,458 |
Jan 21, 2007 10:38 AM Last Post: Justin Brimm |
|
| Can't use NSString to put a number on screen? | kensuguro | 3 | 4,258 |
Nov 7, 2005 01:16 AM Last Post: Jordan |
|
| Even Number of Triangles for Any 3D model | unknown | 1 | 2,516 |
Sep 21, 2005 08:34 AM Last Post: Zekaric |
|
| random number | Kaamoss | 14 | 4,944 |
May 13, 2005 03:03 AM Last Post: DoG |
|

