0

各行が配列に入れられるように、以下の文字列を解析したいと思います。

次の文字列を 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

成分文字列を保持する必要がありますか?

4

3 に答える 3

0

@ggrana のおかげで理解できました。オブジェクトは String 型ではなく、NSArray 型でした。もう解析する必要はありません。私はこれをチェックしました

if ([idont isKindOfClass:[NSArray class]]){
 NSLog(@"*****************YEA %@", idont);
}
于 2013-06-26T19:05:08.667 に答える