我想解析下面的字符串,以便将每一行放入一个数组中。
我有以下字符串作为 NSString:
(
"2 ripe avocados",
"1/2 small onion, minced",
"1 clove garlic, minced",
"1 small jalape\U00f1o, stems and seeds removed, minced",
"2 tablespoons cilantro leaves, finely chopped",
"1 tablespoon of fresh lime juice",
"1/2 teaspoon coarse salt",
"A dash of freshly grated black pepper",
"1 Roma tomato, chopped",
"4 slices crusty white bread",
"4 slices Cheddar cheese",
"Butter, for buttering bread"
)
我尝试了以下方法:
NSCharacterSet* charset = [NSCharacterSet characterSetWithCharactersInString:@"()"];
NSString *newStr = _recipe.ingredients;
newStr = [newStr stringByTrimmingCharactersInSet:charset];
NSArray* array = [newStr componentsSeparatedByString:@"\","];
NSCharacterSet* charset2 = [NSCharacterSet characterSetWithCharactersInString:@"\""];
NSString *ingredientString = [[array objectAtIndex:0] stringByTrimmingCharactersInSet:charset2];
NSLog(@"%@", ingredientString);
但我得到一个 lldb 错误:
-[__NSCFArray stringByTrimmingCharactersInSet:]: unrecognized selector sent to instance 0x200a8d90
我需要保留配料串吗?