Here is a little perl script calledstripper.pl
which removes everything that looks like an HTML / SGML / XML tag:Be sure to chmod +x the script. Add it to your project, add a new "Copy Files" phase, and have it stick this script into the Executables directory.#!/usr/bin/perl while (<>) { $_ =~ s/<[^>]*>//gs; print $_; }This method will take a string and feed it through the perl script:
- (NSString *) stringStrippedOfTags: (NSString *) string { NSBundle *bundle = [NSBundle mainBundle]; NSString *stripperPath; stripperPath = [bundle pathForAuxiliaryExecutable: @"stripper.pl"]; NSTask *task = [[NSTask alloc] init]; [task setLaunchPath: stripperPath]; NSPipe *readPipe = [NSPipe pipe]; NSFileHandle *readHandle = [readPipe fileHandleForReading]; NSPipe *writePipe = [NSPipe pipe]; NSFileHandle *writeHandle = [writePipe fileHandleForWriting]; [task setStandardInput: writePipe]; [task setStandardOutput: readPipe]; [task launch]; [writeHandle writeData: [string dataUsingEncoding: NSASCIIStringEncoding]]; [writeHandle closeFile]; NSMutableData *data = [[NSMutableData alloc] init]; NSData *readData; while ((readData = [readHandle availableData]) && [readData length]) { [data appendData: readData]; } NSString *strippedString; strippedString = [[NSString alloc] initWithData: data encoding: NSASCIIStringEncoding]; [task release]; [data release]; [strippedString autorelease]; return (strippedString); } // stringStrippedOfTags