String manipulation of a http response

I will like to separate into different vars some information from a http response, at the momment im just printing to the serial port the raw data, using:

Serial.print((const char*) Ethernet::buffer + off);

And that prints:

HTTP/1.1 200 OK Date: Wed, 21 Nov 2012 22:47:21 GMT Server: Apache Vary: Accept-Encoding Connection: close Content-Type: text/html

Temp = 28...

I wonder how can I extract the information I need for later analisys, like the http response code (200), the date, and the value of Temp, how can I extract this values into vars? Thanks for any help!

First, your post title is wrong. You do not have a String. We’d just laugh at you if you did. You have a string. That’s a completely different thing.

There are dozens of string functions, defined in string.h. The one that I would start with is strtok() to tokenize the string. Break the whole string into smaller parts, using the embedded \n as the delimiter.

Make a copy of the token and parse the copy. This is even easier if you know that the token that you want to copy/parse is the 1st, second, or nth token. That way, you don’t have to parse each record.

You can look for certain phrases in the token, to decide whether to copy and parse (later) that particular record.

Using strtok() to parse the big string, you’d get tokens like “HTTP/1.1 200 OK”, “Date: Wed, 21 Nov 2012 22:47:21 GMT”, 'Server: Apache", etc. Since the first token contains data of interest, make a copy, using strdup(). The second one does to, so copy it. Then, skip the tokens that do not contain “Temp”.

When you are done, you have at most three new strings to parse (and free).

There is a library called textfinder.h that can extract desired data from an incomming stream of characters. The below should have some examples.

https://www.google.com/search?hl=en&as_q=textfinder.h&as_epq=&as_oq=&as_eq=&as_nlo=&as_nhi=&lr=&cr=&as_qdr=all&as_sitesearch=http%3A%2F%2Farduino.cc%2Fforum&as_occt=any&safe=images&tbs=&as_filetype=&as_rights=