Try this:
Let's say you have the array of strings:
NSArray *arr=@[@"box3523sfgsg",@"boxsdfsdf3",@"bag!@$#",@"!@@4bag",@"tube@#$FR",@"tubeASAD"];
In your case, the above array is filled with following string
[NSString stringByAppendingFormat:@"<p style=\"padding-left:20px;margin-bottom:-10px;\"><i>%@%@%@%@</i></p>",
wrappingBy, pack1, pack2, strFirmName];
Now add the wrappingBy
param to the array everytime you add the above string to the array, and make sure you don;t add duplicates to the array. YOu can check the duplicates before adding them to the array.
and in your case, you would do
NSMutableArray *arrayNAme=[[NSMutableArray alloc]init];
//make arrayName mutable
if (![arrayNAme containsObject: wrappingBy]) {
[arrayNAme addObject: wrappingBy];
}
you will get arrayNAMe contain following:
arrayNAme=@[@"box",@"bag",@"tube"];
Now search the main array string if it contains the wrapingBy names or not, if YES, add them to an array and add that array to the dicitonary:
NSMutableDictionary *myDictionary=[[NSMutableDictionary alloc]init];
for( NSString *nameString in arrayNAme) {
NSMutableArray *strnArray=[[NSMutableArray alloc]init];
for (NSString *str in arr)
{
if([str containsString:nameString])
{
[strnArray addObject:str];
[myDictionary setValue:strnArray forKey:nameString];
}
}
}
At the end you have the dictionary:
{
bag = (
"bag!@$#",
"!@@4bag"
);
box = (
box3523sfgsg,
boxsdfsdf3
);
tube = (
"tube@#$FR",
tubeASAD
);
}
Now you can get each key value and store them in a separate array.