0

i think it is a simple question but i dont know how to solve it.

i have a NSString that containes html content.

i want to extract some tags.

NSString *string=@"test some text <img src='http://www.xyz.com/a.jpg' > blah blah <a href='asdfg'>aaaa</a> bbbb cccc";

i want to take img & "a" tag into new string. then i will display it in UIWebView.

how can i parse it?

tester
  • 103
  • 1
  • 3
  • Will the string always be that simple or could it be any arbitrary HTML from which you need to extract img and a tags? – JeremyP Oct 12 '10 at 15:31
  • i will just extract img, a and iframe tags into another string, then i will display the new string in a webview. – tester Oct 12 '10 at 19:55

2 Answers2

1

The best way is to write a partial tag parser. This is not very difficult.

Another option is to simply find the position of src=' and then the position of the closing "`" and then take the string in between.

You can do this with NSString's rangeOfString: methods.

Stefan Arentz
  • 34,311
  • 8
  • 67
  • 88
1

You can use Regular Expressions, I have used this library to scrape web pages in the iPhone http://regexkit.sourceforge.net/RegexKitLite/index.html

GuidoMB
  • 2,191
  • 3
  • 25
  • 40