开发者

NSScanner’s scanString:intoString doesn’t seem to work

NSString *markdown = @"This is the *Markdown* syntax.";
NSScanner *aScanner = [NSScanner scannerWithString:markdown];

if ([aScanner sc开发者_如何学编程anString:@"*" intoString:nil] == YES) {
    NSLog(@"YES");
}
else {
    NSLog(@"NO");
}

Output:

NO

Why is my output the way it is? Shouldn’t it be YES since the Markdown string has an asterisk? And if it was to work would I get YES twice since I have two asterisk in the Markdown string?


Because the scanner is starting at the start of the string, and you're saying that the next substring should be @"*", but the string you gave it starts with @"T". Maybe you want -scanUpToString:intoString: instead?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜