Removing HTML from NSString causes issues

Griegaiff

New Member
I made a RSS reader, and I'm parsing the description, but there are HTML tags in the description, so I created a category of NSString with the following method to weed out the tags:\[code\]- (NSString *)stripTags:(NSString *)str{NSMutableString *html = [NSMutableString stringWithCapacity:[str length]];NSScanner *scanner = [NSScanner scannerWithString:str];scanner.charactersToBeSkipped = NULL;[scanner setCharactersToBeSkipped:nil];NSString *tempText = nil;while (![scanner isAtEnd]){ [scanner scanUpToString:@"<" intoString:&tempText]; if (tempText != nil) [html appendString:tempText]; [scanner scanUpToString:@">" intoString:NULL]; if (![scanner isAtEnd]) [scanner setScanLocation:[scanner scanLocation] + 1]; tempText = nil;}return html;}\[/code\]This works well in removing the HTML tags, that's not the issue. The issue is that I have the description set to be a maximum of 100 characters in length, but it's still counting the removed HTML tags in that character count. So some descriptions don't show up at all, or some are very short. I need to know how I can remove the HTML tags so that they don't take up any of the character count.If you need, here's where I'm setting my description:\[code\]NSString *dots;int length = [self.description length];if (length > 100){ length = 100; dots = [NSString stringWithFormat:@"..."];}else{ dots = [NSString stringWithFormat:@""];}NSString *description = [NSString stringWithFormat:@"%@%@", [self.description substringToIndex:length], dots];\[/code\]
 
Back
Top