The aim is to get the names and integers from this string and store them for use as variables, but I am confused as to how go about it, I've gotten so far as it just prints out the results, but I don't know what to do next. Heres my code:
String parseString = "value1=123&value2=123&value3=123";
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop() {
parsePlease();
delay(5000);
}
void parsePlease() {
char parseThis[parseString.length()];
parseString.toCharArray(parseThis, parseString.length());
char *ptr = strtok(parseThis, "=&");
while (ptr != NULL)
{
Serial.println(ptr);
ptr = strtok(NULL, "=&");
}
}
It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).
The code should work, in your while loop try to add Serial.flush() or 50ms of delay after Serial.println. Depending on where you get the "parseString" from it could be better to parse it during reading (eg. from Serial).