Convert NSString to int

Tags:

 

 

Example code how to convert NSString to int and how to convert int to NSString.
Using:
Xcode 4.2.1
Mac OS X 10.7.2
Cocoa
 
From NSString to int

 

int intValue;

NSString *strValue = @"0";

intValue = [strValue intValue];
 

intValue should be 0
 
From int to NSString

 

int intValue = 1;

NSString *strValue = @"";    

strValue = [NSString stringWithFormat:@"%i",intValue];
 

strValue should be 1
 

 

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.