我想在循环中创建一个逗号分隔的字符串,如下所示: -
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"]]];
}
此处_arrayToCarryDataFromCartToPaymentPageInPaypal
是MutableArray
来自plist
。
答案 0 :(得分:5)
从PRODUCT
获取_arrayToCarryDataFromCartToPaymentPageInPaypal
数组,然后在其上使用componentsJoinedByString
,以,
分隔字符串。
NSArray *products = [_arrayToCarryDataFromCartToPaymentPageInPaypal valueForKey:@"PRODUCT"];
NSString *str = [products componentsJoinedByString:@","];