Removing HTML tags in an NSString object

371 views
Skip to first unread message

anfernee

unread,
Nov 11, 2009, 2:14:33 AM11/11/09
to Google Data APIs Objective-C Client Library Discussion
Hi,

Can any one guide as to how i can remove the HTML tags within my
string?

Illustration:
From:
NSString *sampleString = "This is the main content. <img src="http://
www.site.com......../>"

I want to have the value of the sampleString to only be "This is the
main content." without the <img> tag.

Anyone here can somehow direct me to this? Thanks...

Greg Robbins

unread,
Nov 11, 2009, 3:22:32 AM11/11/09
to gdata-objec...@googlegroups.com
On the Mac, you can use an NSAttributedString to remove html tags, like

  NSString *htmlStr = @"Foo <img src=\"http://www.site.com'\" /> Bar.";
  NSData *data = [htmlStr dataUsingEncoding:NSUTF8StringEncoding]; 
  NSAttributedString *attrStr = [[[NSAttributedString alloc] initWithHTML:data
                                                       documentAttributes:nil] autorelease];
  NSString *plainStr = [attrStr string];

I'm not sure if there is a similarly straightforward way on the iPhone.

Reply all
Reply to author
Forward
0 new messages