NSString *markdown = @"This is the *Markdown* syntax.";
NSScanner *aScanner = [NSScanner scannerWithString:markdown];
if ([aScanner scanString:@"*" 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?