Reputation: 98
I am trying to scan for a specific string in an html file, assign it to an NSString then do things with the NSString. If it matters, I am doing this in Cocos2d.
My code looks like this:
NSScanner *scanner = [NSScanner scannerWithString: htmlCodeString];
NSString* string;
[scanner scanUpToString:@"HTML CODE" intoString:NULL];
[scanner scanString:@"HTML CODE" intoString:NULL];
[scanner scanUpToString:@"STRING I NEED" intoString: &string];
NSLog(@"%@", string);
When I run the code, NSLog prints the name of the layer I am executing the code in.
I am confused because I followed this example by Apple to a T: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/Scanners.html#//apple_ref/doc/uid/20000147-BCIEFGHC (scroll to the bottom)
Any advice would be greatly appreciated.
Upvotes: 1
Views: 89
Reputation: 53551
Check what scanUpToString:intoString
returns. If it returns NO
, the string wasn't found and the "into" string isn't modified. As you don't initialize your string, it contains some random garbage. You should initialize it to nil
and then look into why your string isn't found.
Upvotes: 2