In PHP when I have multiple variables, I can put them all together so when I print the same text several times throughout the code it's always the same. Something like:
Code:
$var1 = "Hi";
$var2 = "What's Up?";
$var3 = $var1.$var2;
echo $var3;
// produces "HiWhat's Up?"
I want to do something similar in Objective-C but I can't figure it out. Here is what I have:
Code:
NSString * lastName = [anObject valueForProperty:kABLastNameProperty];
NSString * firstName = [anObject valueForProperty:kABFirstNameProperty];
printf("$addrBook[\"%s%s%d\"]", [lastName UTF8String], [firstName UTF8String], arrIndex);
arrIndex is an integer, lastName and firstName are NSStrings. I want to all the text into a variable once, and just print out that when I need it. Right now, I'm reusing the printf() line multiple times so it's always parsing through. If I could just set the string and print it, it'd be better.
Second problem, how do I change that integer into a string. I was forced to use %d because I couldn't for the life of me find a function that would convert the integer to a string. I tried [arrIndex stringValue] but that didn't work. Any ideas?
Thanks in advance. I'll keep posting my problems as I come across them.
