Please forgive the simplicity of the question. I'm completely new to Objective C.
I'd like to know how to concatenate integer and string values and print them to the console.
This is what I'd like for my output:
10 + 20 = 30
In Java I'd write this code to produce the needed results:
System.Out.Println(intVarWith10 + " + " + intVarWith20 + " = " + result);
Objective-C is quite different. How can we concatenate the 3 integers along with the strings in between?
You can use following code
int iFirst,iSecond;
iFirst=10;
iSecond=20;
NSLog(@"%@",[NSString stringWithFormat:@"%d + %d =%d",iFirst,iSecond,(iFirst+iSecond)]);
Take a look at NSString
- it has a method stringWithFormat that does what you require. For example:
NSString* yString = [NSString stringWithFormat:@"%d + %d = %d",
intVarWith10, intVarWith20 , result];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With