如何在由逗号分隔的NSMutableString中添加多个字符串

时间:2017-02-04 06:15:50

标签: ios objective-c

我想在循环中创建一个逗号分隔的字符串,如下所示: -

string=@"A,B,C,D,E";    

我做了类似的事情:

for (int j=0; j<_arrayToCarryDataFromCartToPaymentPageInPaypal.count; j++)    
{    
  NSMutableDictionary *paypalArrayDataInDictionary=[_arrayToCarryDataFromCartToPaymentPageInPaypal objectAtIndex:j];    
  [productNameDetail appendString:[NSString stringWithFormat:@"%@,", [paypalArrayDataInDictionary objectForKey:@"PRODUCT"]]];    
}  

此处_arrayToCarryDataFromCartToPaymentPageInPaypalMutableArray来自plist

1 个答案:

答案 0 :(得分:5)

PRODUCT获取_arrayToCarryDataFromCartToPaymentPageInPaypal数组,然后在其上使用componentsJoinedByString,以,分隔字符串。

NSArray *products = [_arrayToCarryDataFromCartToPaymentPageInPaypal valueForKey:@"PRODUCT"];
NSString *str = [products componentsJoinedByString:@","];