Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
my coffee doesn't seem to be working just yet:

Code:
if (licenseDictionary == nil)
	return @"Goodbye!";
	else
	[B]return @"Hello " [licenseDictionary objectForKey:@"Full Name"];[/B]

i can't seem to remember how to properly merge the bold statement above... "Hello " will always be there, but Full Name will change... it's a syntax error, and i'm not even sure i can change portions of a string dynamically...

any thoughts?
 

tacoman667

macrumors regular
Mar 27, 2008
143
0
Can you add a "+" between the 2 items or my guess would be you need to use a concatinating method in NSString. Something like
Code:
 return [NSString stringFromObjects:@"Hello ", <Other Obj...>];
.

This woul dbe just a guess as I haven't done that yet and I haven't finished my book yet either.
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
Can you add a "+" between the 2 items or my guess would be you need to use a concatinating method in NSString. Something like
Code:
 return [NSString stringFromObjects:@"Hello ", <Other Obj...>];
.

This woul dbe just a guess as I haven't done that yet and I haven't finished my book yet either.

the comma doesn't work, as only the last object in the sentence is executed... and adding "+" only seems to give syntax errors...
 

mysticwhiskey

macrumors newbie
Mar 31, 2008
25
0
my coffee doesn't seem to be working just yet:

Code:
if (licenseDictionary == nil)
	return @"Goodbye!";
	else
	[B]return @"Hello " [licenseDictionary objectForKey:@"Full Name"];[/B]

i can't seem to remember how to properly merge the bold statement above... "Hello " will always be there, but Full Name will change... it's a syntax error, and i'm not even sure i can change portions of a string dynamically...

any thoughts?

Hi,

+[NSString stringWithFormat] will do what you want:

Code:
if (licenseDictionary == nil)
    return @"Goodbye!";
else
    [B]return [NSString stringWithFormat:@"Hello %@", [licenseDictionary objectForKey:@"Full Name"]];[/B]

The %@ symbol applies to objects. The -[NSObject description] message is sent to the object, which for an NString object is equal to the string value.
 

tacoman667

macrumors regular
Mar 27, 2008
143
0
I knew it was something like that. I use StringFormat alot in my C# programming but C# is all dot modifiers. Messaging is completely new to me and I do not know all the static methods in each class yet. Sorry about that!
 

hazmatzak

macrumors regular
Apr 29, 2008
135
0
If you really are just tacking two strings together, you might also consider -stringByAppendingString
Code:
return [@"Hello " stringByAppendingString:[licenseDictionary objectForKey:@"Full Name"]];
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
I knew it was something like that. I use StringFormat alot in my C# programming but C# is all dot modifiers. Messaging is completely new to me and I do not know all the static methods in each class yet. Sorry about that!

no prob tacoman, thanks for the suggestions, it was worth a shot.

If you really are just tacking two strings together, you might also consider -stringByAppendingString
Code:
return [@"Hello " stringByAppendingString:[licenseDictionary objectForKey:@"Full Name"]];

good to know. thanks hazmatzak.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.