I’m using this method to find the first <> couple into a string (XML content) :
NSScanner* scanner = [NSScanner scannerWithString:contentToParse];
int startPos = 0;
int endPos = 0;
// Open search
if ([scanner scanString:@"<" intoString:nil]) {
startPos = [scanner scanLocation]-1;
NSLog(@"found '<' at pos %i", startPos);
// close search
if ([scanner scanString:@">" intoString:nil]) {
endPos = [scanner scanLocation]-1;
NSLog(@"found '>' at pos %i", endPos);
NSString* tag = [contentToParse substringWithRange:NSMakeRange(startPos, endPos-startPos)];
NSLog(@"Tag found : %@", tag);
}
}
but only “found ‘<‘ at pos 0” is logged.
My XML content contains many many <> items…
Why is that method not working ?
scanString:intoString:tries to scan the string parameter at the current location. If such string is not present at the current location, it simply returnsNO.You may want use
scanUpToString:intoString:(reference) instead, which scans advancing the scan location until the given string is encountered.