extract specific string in NSString

五迷三道 提交于 2019-12-14 00:42:01

问题


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?


回答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.




回答2:


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



来源:https://stackoverflow.com/questions/3915146/extract-specific-string-in-nsstring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!