Asked 9 days ago
12 Feb 2017
Views 279
fatso

fatso posted

concat multiple NSString in one String in objective c

i have multiple NSString which is dynamic input from app.

   NSString *test1=@"This";
   NSString *test2=@"is";
   NSString *test3=@"my";
   NSString *test4=@"Test";

need to concat multiple NSString in one String in objective c .

shyam

shyam
answered Feb 21 '18 20:17

append string by stringByAppendingString


    NSString *append =[test1 stringByAppendingString:[seperator stringByAppendingString:test2]];
    append =[append stringByAppendingString:[seperator stringByAppendingString:test3]];
    append =[append stringByAppendingString:[seperator stringByAppendingString:test4]];

Edit Answer
Share
ravi

ravi
answered Feb 21 '18 20:17


 NSString *test1=@"This";
 NSString *test2=@"is";
 NSString *test3=@"my";
 NSString *test4=@"Test";
    
NSArray *myStrings = [[NSArray alloc] initWithObjects:test1, test2, test3, test4, nil];
NSString *joinedString = [myStrings componentsJoinedByString:@"|"];


append the string to one array


NSArray *myStrings = [[NSArray alloc] initWithObjects:test1, test2, test3, test4, nil];


join array value to string

NSString *joinedString = [myStrings componentsJoinedByString:@"|"];

Edit Answer
Share
Mitul Dabhi

Mitul Dabhi
answered Feb 21 '18 20:17

use stringWithFormat to append string with specified format.


   NSString *append =[NSString stringWithFormat:@"%@ , %@ , %@ , %@ ",test1,test2,test3,test4];
    NSLog(append);
Edit Answer
Share
Post Answer