我是新人,这是我的第一篇文章。
在我的输入流中,我得到消息列表,我必须过滤特定行并打印该行,但有时候它会崩溃,任何人都可以告诉我我在哪里弄错了吗?
这是我的代码:
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];
我得到了:
&xyz;123:183:184:142&
&abc;134:534:435:432&
&qwe;323:535:234:532&
有时我会得到:
&qwe;323:535:234:532&
&abc;423:123:423:341&
&gfg;434:243:534:3434&
我想只打印字符串以“& abc”开头,以“&”结尾..
代码是否正确?有什么建议吗?