On 19 Dec 2008, at 09:43, Scott Wilson wrote:
Something like this: void pTagsToDivTags(NSMutableString* html) { NSRange styleOpen = [html rangeOfString: @"<style"]; NSRange styleClose = [html rangeOfString: @"</style>"]; if(styleClose.location != NSNotFound) { // classes to IDs NSRange searchRange = NSMakeRange(styleOpen.location, styleClose.location - styleOpen.location); NSUInteger replacements = [html replaceOccurrencesOfString:@"p.p" withString:@"#p" options:NSCaseInsensitiveSearch range:searchRange]; // now replace all <p> tags with <div> if(replacements > 0) { NSRange bodyOpen = [html rangeOfString: @"<body"]; NSRange bodyClose = [html rangeOfString: @"</body>"]; searchRange = NSMakeRange(bodyOpen.location, bodyClose.location - bodyOpen.location); [html replaceOccurrencesOfString:@"<p class=" withString:@"<div id=" options:NSCaseInsensitiveSearch range:searchRange]; searchRange = NSMakeRange(bodyOpen.location, [html rangeOfString: @"</body>"].location - bodyOpen.location); [html replaceOccurrencesOfString:@"</p>" withString:@"</div>" options:NSCaseInsensitiveSearch range:searchRange]; } } } |