开发者

Get the a part of content from NSString

I want to ask something about the NSString in objective C. I use the following code to retrieve some of the HTML content.

NSHTTP开发者_运维问答URLResponse *response = nil;  
NSError *error = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data = [[NSString alloc]initWithData:responseData encoding:NSUTF8StringEncoding];

In the data, it contains lot of HTML code e.g.

<!DOCTY... >
...
// retrieve the content from <form> to </form>
<form method="post" action="...">
    <input type="..." name="name_1" value="value_1" />
    <input type="..." name="name_2" value="value_2" />
</form>
...    
</html>

I want to get the content of the name_1, value_1, name_2 and value_2 to and NSString, just like

NSString A = "name_1"

NSString B = "value_1"

NSString C = "name_2"

NSString D = "value_2"

Does the NSString provide this kind of search or method to retrieve the string? Thank you very much.


NSString can and does but it would be very messy.

If you are intent on parsing the NSString take a look a NSScanner, otherwise check out parsing using the NSXMLDocument

--Frank

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜