ios - Remove broken HTML tags from NSString -


my webservice returning me html content, html string might contains incomplete html tags

e.g: "this broken html tag <b" 

or similler,

now converting nsattributedstring during incomplete tags causing problems, solved if remove these incomplete html tags nsstring, suggestions how it?

try code

- (nsstring *)removeincompletehtmltaginstring:(nsstring *)htmlstring {     nsarray *substringbyopentabs = [htmlstring componentsseparatedbystring:@"<"];     nsarray *substringbyclosetabs = [htmlstring componentsseparatedbystring:@">"];     if (substringbyopentabs.count > substringbyclosetabs.count) {         return [htmlstring substringtoindex:(htmlstring.length - ((nsstring *)[substringbyopentabs lastobject]).length) -1];     }     else {         return htmlstring;     } } 

test:

nslog(@"%@",[self removeincompletehtmltaginstring:@"this <xx> broken html tag<b"]); 

output is: "this <xx> broken html tag"


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -