Does anyone know if NSScanner will scan properly when a \n is added to the string?
For example, i have a string to scan (myString) “\nTest\nSuper\n”
NSScanner *scanner = [NSScanner scannerWithString:myString];
NSString *str = @"Super";
if( [scanner scanString:str intoString:nil] )
{
//It never reaches here
}
Any ideas why it fails to see “Super”? This used to work when I didn’t have the \n sign.
Thanks
-[NSScanner scanString:intoString:]returnsNObecause you’re attempting to scan from the beginning of the string, and the substring ‘Super’ doesn’t occur there.I’ll use this to try to illustrate what happens:
The reason the first newline character is ignored is that your scanner (the way you have set it up) ignores whitespace and newlines by default, and so it skips the first one. At the end, again, because it skips whitespace and newlines,
whatDidIGetis nil.EDIT:
If you inserted this immediately after instantiating your scanner:
You’d see all your newline characters in
whatDidIGetfor the first and third scans.Best wishes to you in your endeavors.