Asked 7 years ago
12 Feb 2017
Views 2399
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 Nov 30 '-1 00:00

append string by stringByAppendingString


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

ravi

ravi
answered Nov 30 '-1 00:00


 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:@"|"];

Mitul Dabhi

Mitul Dabhi
answered Nov 30 '-1 00:00

use stringWithFormat to append string with specified format.


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