I have 5 String i want that they must be store in singe NSString all the values separate with |
sign
NSString *first=@\"Ali\";
NSString *
To improve on Nitish's answer, you can reduce the number of lines by following this:
NSString *first=@"Ali";
first = [first stringByAppendingString:[@"|" stringByAppendingString:[@"Imran" stringByAppendingString:@"|"]]];
.
NSArray *stringsArray = [[NSArray alloc] initWithObjects:first, second, third, fourth, fifth, nil];
NSString *combinedString = [stringsArray componentsJoinedByString:@","];
The combined String looks like this @"Ali,Imran,AliImran,ImranAli,Ali Imran Jamshed"
;
NSArray *myStrings = [[NSArray alloc] initWithObjects:first, second, third, fourth, fifth, nil];
NSString *joinedString = [myStrings componentsJoinedByString:@"|"];
// release myStrings if not using ARC.
Short solution:
NSString *str = [@[nstring1, nstring2, nstring3] componentsJoinedByString:@","];
I guess what DrummerB suggested, is the best way. You have to store the strings in data structure. Array or dictionary for that matter.
If you just want to use strings it is not impossible, but it will be unwise. Here you go :
NSString*first=@"Ali";
first = [first stringByAppendingString:@"|"];
first = [first stringByAppendingString:@"Imran"];
first = [first stringByAppendingString:@"|"];
first = [first stringByAppendingString:@"AliImran"];
first = [first stringByAppendingString:@"|"];
first = [first stringByAppendingString:@"ImranAli"];
first = [first stringByAppendingString:@"|"];
first = [first stringByAppendingString:@"Ali Imran Jamshed"];
you can try ....
NSString *joinString=[NSString stringWithFormat:@"%@|%@|%@|%@|%@",youstring1,youstring2,youstring3,youstring4,youstring5];