views:

28

answers:

1

Hi, everyone,

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

NSHTTPURLResponse *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.

A: 

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

Frank C.