私はNSSringを持っています:
NSString *example = @"'example01','example02','example03','example04'";
この行NSArrayからどのように作成できますか?
NSString *example = [example stringByReplacingOccurrencesOfString:@"'" withString:@""];
NSArray * exampleArr = [example componentsSeparatedByString:@","];
NSArray *commaSeparatedComponents = [example componentsSeparatedByString:@","];
NSCharacterSet *quotesSet = [NSCharacterSet characterSetWithCharactersInString:@"'"];
for (NSString *component in commaSeparatedComponents) {
NSString *correctlyTrimmedComponent = [component stringByTrimmingCharactersInSet:quotesSet]; // only remove 's at the edges
// ... do something with each component; maybe add to a mutable array ...
}
これには、値の内部に存在する引用符を削除しないという他の回答よりも優れていますが、データ内で必要だった可能性のある引用符のエスケープなどを実際に解決することはできません。それでも一部の文字列では誤動作しますが、削除する引用符についての軽率さが少ないため、誤動作するケースは少なくなります。
これが正確な形式の文字列を超えている場合は、引用符のエスケープ方法のセマンティクスを処理したり、ガベージを適切に処理したりできる、この種の文字列のパーサーが必要になる可能性があります。