-5

我有一个字符串 category=AC,Credit,Entertainment,Bars; 我想将此字符串与 ns 数组中的逗号分开,例如 myarray=(AC,Credit,Entertainment,Bars)

    myCategory=[restaurantInfo objectForKey:@"specialCriteria"];

NSMutableArray *newArray3 = [[NSMutableArray alloc]init];


      [newArray3 addObject:[myCategory componentsSeparatedByString:@","]];
NSLog(@"new array=%@",newArray3 );

我的类别是我的 NSString,restaurantInfo 是我的 nsmutable 字典,它从用户默认值中检索值。代码仅分隔第一个值,输出为

新数组=((AC,“酒吧”,“信用卡”,“娱乐”))

请帮助。在此先感谢

4

2 回答 2

0

你要:

myCategory = restaurantInfo[@"specialCriteria"];

NSArray *newArray3 = [myCategory componentsSeparatedByString:@","];
NSLog(@"new array = %@", newArray3);
于 2013-11-01T04:46:33.970 回答
0

试试这个:

myCategory=[restaurantInfo valueForKey:@"specialCriteria"];
NSArray *pathParts = [myCategory componentsSeparatedByString:@","];
于 2013-11-01T04:51:27.420 回答