Reputation: 71
I want to create a comma separated string inside loop like this :-
string=@"A,B,C,D,E";
I did something like this :
for (int j=0; j<_arrayToCarryDataFromCartToPaymentPageInPaypal.count; j++)
{
NSMutableDictionary *paypalArrayDataInDictionary=[_arrayToCarryDataFromCartToPaymentPageInPaypal objectAtIndex:j];
[productNameDetail appendString:[NSString stringWithFormat:@"%@,", [paypalArrayDataInDictionary objectForKey:@"PRODUCT"]]];
}
Here _arrayToCarryDataFromCartToPaymentPageInPaypal
is my MutableArray
getting from plist
.
Upvotes: 0
Views: 415
Reputation: 72410
Get array of PRODUCT
from the _arrayToCarryDataFromCartToPaymentPageInPaypal
and then use componentsJoinedByString
on it to get the string separated by ,
.
NSArray *products = [_arrayToCarryDataFromCartToPaymentPageInPaypal valueForKey:@"PRODUCT"];
NSString *str = [products componentsJoinedByString:@","];
Upvotes: 5