extract specific string in NSString

2019-06-11 13:45发布

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?

2条回答
我只想做你的唯一
2楼-- · 2019-06-11 14:09

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

查看更多
趁早两清
3楼-- · 2019-06-11 14:30

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.

查看更多
登录 后发表回答