0

Possible Duplicate:
How do I concatenate strings in Objective-C?

I have two strings and wish to make a third string which combines the two by concatenating them.

NSString *a = a;
NSString *b = b;
NSString *c = a+b;

The problem is that Xcode does`t let me do a+b, so I don't know how to add strings. I've also tried this:

NSStirng *c = @"%@%@",a,b;

But it doesn't work too. Please help me with this noob question!

Thank you!

Community
  • 1
  • 1
Adri
  • 243
  • 3
  • 12

3 Answers3

13
NSString *c = [NSString stringWithFormat:"%@%@", a, b]

or

NSString *c = [a stringByAppendingString:b];

The latter being slightly more efficient.

Adam Wright
  • 48,938
  • 12
  • 131
  • 152
1

Try

NSString *c = [a stringByAppendingString: b];
Costique
  • 23,712
  • 4
  • 76
  • 79
0
NSString *c = [NSString stringWithFormat:@"%@%@", a, b];
Ell Neal
  • 6,014
  • 2
  • 29
  • 54