0

How to plus NSString? Example:

NSString *a=@"hello";
NSString *b=@"world";
NSString *s=@"";

I want:

s = "helloworld";

Thank for helping.

Thorsten Dittmar
  • 52,871
  • 8
  • 78
  • 129
  • 1
    You could also try the search function. This brought up [this question][1]. [1]: http://stackoverflow.com/questions/510269/how-do-i-concatenate-strings – Thorsten Dittmar Nov 26 '12 at 17:26

5 Answers5

1

Please use below code.

NSString *s= [NSString stringWithFormat:@"%@%@", a, b];
Paramasivan Samuttiram
  • 3,728
  • 1
  • 21
  • 28
1

What you are talking about is concatenating. And you need to use:

NSString *a = @"This ";
NSString *b = @"is a string";
NSString *c= [NSString stringWithFormat:@"%@%@", a, b];

Check out: objective-c strings a guide for beginners for a full list.

NANNAV
  • 4,718
  • 4
  • 26
  • 48
0

You can also use stringByAppendingString: like so -

NSString *completeString = [a stringByAppendingString:b];
Imirak
  • 1,303
  • 11
  • 21
0
NSString *a=@"hello";    
NSString *b=@"world";    
NSString *s=[NSString stringWithFormat:@"%@%@", a, b];
Rahul
  • 3,401
  • 3
  • 13
  • 27
0
NSString *completeString = [a stringByAppendingString:b];

This function is Good and Easy...

qn5566
  • 1
  • 1