Getting Number From Character In NSString

Posts: 1,066
Joined: 2004.07
Post: #1
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?

SupplyCrate *crate = [crateList objectAtIndex:[NSNumber numberWithChar:[missileStatus characterAtIndex:1]]];
Quote this message in a reply
Posts: 78
Joined: 2002.06
Post: #2
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'
Quote this message in a reply
Posts: 1,066
Joined: 2004.07
Post: #3
Thanks. Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Malloc() Struct with NSString Inside? Graphic Ace 3 6,813 Jan 26, 2010 05:32 PM
Last Post: mysteriouspants
  What do you want to see in a Random Number Generator? Justin Brimm 16 12,226 Jan 21, 2007 10:38 AM
Last Post: Justin Brimm
  Can't use NSString to put a number on screen? kensuguro 3 6,723 Nov 7, 2005 01:16 AM
Last Post: Jordan
  Even Number of Triangles for Any 3D model unknown 1 4,141 Sep 21, 2005 08:34 AM
Last Post: Zekaric
  random number Kaamoss 14 9,336 May 13, 2005 03:03 AM
Last Post: DoG