Re: HTML Parsing Follow-up
Re: HTML Parsing Follow-up
- Subject: Re: HTML Parsing Follow-up
- From: Markus Hitter <email@hidden>
- Date: Tue, 22 Jan 2002 14:35:53 +0100
Am Dienstag den, 22. Januar 2002, um 07:39, schrieb Sam Goldman:
There was a short e-mail series on this list about HTML Parsing
and it gave
me a little inspiration to get it working.
I came up with this:
- (void)awakeFromNib
{
NSString *testString = @"This <string> is <a> test <string>";
NSScanner *scanner = [[NSScanner alloc] initWithString:testString];
// this can be done with one method (and you forgot to release
it later, too):
NSScanner *scanner = [NSScanner scannerWithString:testString];
NSString *tmpString = [[[NSString alloc] init] autorelease];
// no need to allocate an empty string here,
// NSScanner methods will return a new, auotreleased one.
NSString *tmpString;
NSMutableString *doneString = [[[NSMutableString alloc] init]
autorelease];
while ([scanner scanUpToString:@"<" intoString:&tmpString])
{
[doneString appendString:tmpString];
// what about this:
while (! [scanner isAtEnd]) {
[scanner scanUpToString:@"<" intoString:&tmpString])
[doneString appendString:tmpString];
[scanner scanString:@">" intoString:nil];
} // end of while loop
Have fun,
Markus
- - - - - - - - - - - - - - - - - - -
Dipl. Ing. Markus Hitter
http://www.jump-ing.de/