Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add concatenate multiple NSString in one String in iphone

I have 5 String i want that they must be store in singe NSString all the values separate with | sign

   NSString *first=@"Ali";
   NSString *second=@"Imran";
   NSString *third=@"AliImran";
   NSString *fourth=@"ImranAli";
   NSString *fifth=@"Ali Imran Jamshed";

I want to all these in single NSString to store and all values separated by given sign.

like image 254
user1619187 Avatar asked Aug 28 '12 09:08

user1619187


2 Answers

NSArray *myStrings = [[NSArray alloc] initWithObjects:first, second, third, fourth, fifth, nil];
NSString *joinedString = [myStrings componentsJoinedByString:@"|"];
// release myStrings if not using ARC.
like image 80
DrummerB Avatar answered Oct 20 '22 18:10

DrummerB


you can try ....
NSString *joinString=[NSString stringWithFormat:@"%@|%@|%@|%@|%@",youstring1,youstring2,youstring3,youstring4,youstring5];
like image 37
Ha cong Thuan Avatar answered Oct 20 '22 18:10

Ha cong Thuan