Skip to content Skip to sidebar Skip to footer

Does Objective C Have A Strip Tags Function?

I am looking for an objective C function (custom or built-in) that strips html tags from a string, similar to PHP's version that can be found here: http://php.net/manual/en/functio

Solution 1:

This just removes < and > characters and everything between them, which I suppose is sufficient:

- (NSString *) stripTags:(NSString *)str
{
    NSMutableString *ms = [NSMutableString stringWithCapacity:[str length]];

    NSScanner *scanner = [NSScanner scannerWithString:str];
    [scanner setCharactersToBeSkipped:nil];
    NSString *s = nil;
    while (![scanner isAtEnd])
    {
        [scanner scanUpToString:@"<" intoString:&s];
        if (s != nil)
            [ms appendString:s];
        [scanner scanUpToString:@">" intoString:NULL];
        if (![scanner isAtEnd])
            [scanner setScanLocation:[scanner scanLocation]+1];
        s = nil;
    }

    return ms;
}

Post a Comment for "Does Objective C Have A Strip Tags Function?"