我想知道如何获取以 &abc 开头并以 & 结尾的特定字符串。我尝试使用 had prefix 和 sufix 。但这不是新线,
&xyz;123:183:184:142&
&abc;134:534:435:432&
&qwe;323:535:234:532&
我的代码:
NSMutableArray *substrings = [NSMutableArray new];
NSScanner *scanner = [NSScanner scannerWithString:s];
[scanner scanUpToString:@"&abc" intoString:nil]; //
NSString *substring = nil;
[scanner scanString:@"&abc" intoString:nil]; // Scan the # character
if([scanner scanUpToString:@"&" intoString:&substring]) {
// If the space immediately followed the &, this will be skipped
[substrings addObject:substring];
NSLog(@"substring is :%@",substring);
}
// do something with substrings
[substrings release];
如何制作“scanner scanUpToString:@"&abc" 并计算 ":"==3 直到 "#"???? 可以帮助我