Re: NSScanner baffling behaviour (scanString:intoString: doesn't work!)
Re: NSScanner baffling behaviour (scanString:intoString: doesn't work!)
- Subject: Re: NSScanner baffling behaviour (scanString:intoString: doesn't work!)
- From: Greg Hurrell <email@hidden>
- Date: Tue, 8 Apr 2003 23:59:46 +0930
Thanks Joar. Is there one case in which your code will fail (correct me
if I am wrong)?
If the string to be scanned is something like, "<title>Hi
there</title>", and the startTag that you are scanning for is
"<title>", then will your first [scanner scanUpToString:startTag
infoString:nil] not return NO, and hence you'll never pass the "if"
statement?
Would this code not be susceptible to that problem?
// putting this on a separate line effectively makes it optional?
[scanner scanUpToString:startTag intoString:nil];
if ([scanner scanString:startTag intoString:nil])
{
if ([scanner scanUpToString:endTag intoString:&result])
return result;
}
return nil;
Cheers
Greg
El Martes, 8 abr, 2003, a las 22:48 Australia/Adelaide, j o a r
escribis:
Try:
if ([scanner scanUpToString: startTag intoString: nil] && [scanner
scanString: startTag intoString: nil])
{
if ([scanner scanUpToString: endTag intoString: &result])
{
NSLog(@"result: %@", result);
}
}
j o a r
On Tuesday, Apr 8, 2003, at 11:51 Europe/Stockholm, Greg Hurrell wrote:
+ (NSString *)_scanString:(NSString *)source
startTag:(NSString *)startTag
endTag:(NSString *)endTag
{
NSScanner *scanner = [NSScanner scannerWithString:source];
NSString *result = nil;
// first try for startTag
if (![scanner scanString:startTag intoString:nil])
// startTag not found!
return nil;
// then end tag
if ([scanner scanUpToString:endTag intoString:&result])
// known bug: if endTag doesn't appear in source string, will
return entire rest of string!
return result;
else
return nil;
}
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.