Retrieve Value from NSString
i have a NSString instance ,i want to retrieve value开发者_开发问答 from it and store it into an integer. This is wat i am doing but its not working.
NSString *totalcnt;
char *str = totalcnt;
int a = atoi(str);
Help me out. Thanks
Taimur
If you are dealing with Objective-C objects, use Objective-C:
int a = [totalcnt intValue];
Reference: intValue
In your code example, you don't instantiate a NSString but I hope your are doing it in your real code. Otherwise, totalcnt
is a wild pointer.
int a = [totalcnt intValue];
精彩评论