Home > DeveloperSection > Forums > Concatenate 2 or more NSString into 1 NSString in Objective-C
Derek Honeybun
Derek Honeybun

Total Post:17

Posted on    November-07-2015 4:13 AM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 791  View(s)
Rate this:
I am new in Objective-C programming, can any one tell me how to Concatenate 2 or more NSString into 1 NSString with comma(,) sign.
For example I have 3 strings like this:
NSString *country1 = @"India";
NSString *country2 = @"China";
NSString *country3 = @"Japan";

I want to make a single string to store and in future I want to separate all these values by given sign.

Tarun Kumar

Total Post:214

Posted on    November-08-2015 11:06 PM

You can use NSArray method 'stringWithFormat: ' to add two or more string variables into an array.

For example:

NSString *Name = @"India"; 

NSString *Code = @"+91";

NSMutableArray *countryObject = [[NSMutableArray alloc]init];

[countryObject addObject:[NSString stringWithFormat:@"%@ %@ %@", Name, @",", Code]];

and also you can see I am concating two strings separated with comma(,) because in future, we can split this string by comma(,) as needed.



Don't want to miss updates? Please click the below button!

Follow MindStick