开发者

How do I strip HTML tags from my feed before displaying them in table cells?

I am read开发者_StackOverflow社区ing a feed which gives the data with some html tags like

<p> this is a test string </p>.

I need to display this in UITableViewCell. The problem I have is , the html tags also gets displayed. How can I just show the text without html tag .??

Any help is greatly appreciated …!!!

Thanks


Just run the string through some stripping code before adding it to your tableview.

NSString *str = @"<p> this is a test string </p>";

str = [str stringByReplacingOccurrencesOfString:@"<p>" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"</p>" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"<h1>" withString:@""];
str = [str stringByReplacingOccurrencesOfString:@"</h1>" withString:@""];
//etc....

//new string equals @"this is a test string"


Depending on your needs you can search & replace those tags, or put the string you get from the server into UIWebView. It should present the html as it is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜