您可以使用 NSScanner 扫描\"
并存储数组中的所有其他子字符串
NSString *string = @"filename.cpp - line: 1 \"comment 1\"\nfilename.cpp - line: 1 \"comment 2\"\nfilename.cpp - line: 1 \"comment 3\"\n";
NSScanner *scanner = [NSScanner scannerWithString:string];
NSMutableArray *array = [NSMutableArray array];
while (YES) {
NSString *s;
[scanner scanUpToString:@"\"" intoString:NULL];
[scanner setScanLocation:[scanner scanLocation]+1];
[scanner scanUpToString:@"\"" intoString:&s];
if(s)
[array addObject:s];
if(![scanner isAtEnd])
[scanner setScanLocation:[scanner scanLocation]+1];
else break;
}
结果:
array = (
comment 1,
comment 2,
comment 3
)