So Im am recieving this data from a client. I have already got the important part and saved it into a string.
GET /favicon.ico HTTP/1.1
I would like to parse this string by white spaces, I am not sure if my method is most effecient.
String textToParse = "GET /favicon.ico HTTP/1.1"
char * duplicate = strdup(requestData.c_str()); //have to covert the string to a char* so that i can use strok
char * pch;
Serial.print("\nSplitting string to tokens:");
Serial.println(requestData);
pch = strtok (duplicate," ");
Serial.println (pch);
pch = strtok (NULL, " ");
Serial.println (pch);
pch = strtok (NULL, " ");
Serial.println (pch);
Splitting string to tokens:GET /favicon.ico HTTP/1.1
GET
/favicon.ico
HTTP/1.1
Can this be further be optimized?
I do it this way because from what i have read HTTP request (GET,POST,DELETE, Etc.) do not have sapces in then and for the second part, URLs also cannot conatiain spaces in them. So i assume it is safe to use the 'space' character as an indicator to split