0

How to convert NSString to Integer...

i mean.

NSString *one=@"1";

i want to get this value like this.. int t=1;

is it possible..?

pls help me thanks and regards... by raju

Raju
  • 3,459
  • 12
  • 37
  • 30
  • possible duplicate of [How to do string conversions in Objective-C?](http://stackoverflow.com/questions/169925/how-to-do-string-conversions-in-objective-c) – Bot Nov 15 '12 at 15:48

2 Answers2

6

NSString has an intValue (or the preferred "integerValue") method that can be used to parse the string to an int.

It would look something like this:

int i = [myString intValue];

Check out the docs here:

http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/intValue

Andy White
  • 86,444
  • 48
  • 176
  • 211
2

You can do something like the following:

NSString *one = @"1";
int t = [one intValue];

More discussion here: How to do string conversions in Objective-C?

Community
  • 1
  • 1
runako
  • 6,132
  • 2
  • 25
  • 15