Abhishek Sharma
Abhishek Sharma

Reputation: 71

How to add multiple strings in NSMutableString separated by comma

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

Answers (1)

Nirav D
Nirav D

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

Related Questions