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!

0

3 Answers 3

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

or

NSString *c = [a stringByAppendingString:b]; 

The latter being slightly more efficient.

Sign up to request clarification or add additional context in comments.

Comments

1

Try

NSString *c = [a stringByAppendingString: b]; 

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.