views:

26

answers:

2

I am currently using this code to put some text on the screen

   userOutput.text=@"";

I want to be able to display an int variable in the string, like you do with printf in C with the %d placeholders. How do I do this with an NSString

+1  A: 

use NSString's +stringWithFormat: method:

 userOutput.text= [NSString stringWithFormat: @"%d", 100];

It uses exactly the same format specifiers as printf function in c.

Vladimir
And besides the C `printf` format specifiers, you can use `%@`, to print the `-description` of any object.
Douwe Maan
A: 
int whatever = 42;
userOutput.text = [NSString stringWithFormat:@"%d", whatever];
walkytalky