问题
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