String class is a terrible, for many subtle reasons. And, Yes, an FSM approach is the most efficient way to watch for a keyword/value pair to “go by”. Because RAM is so limited, you really have to be careful about holding on to an entire “message” (i.e., web page in your case).
Instead, as each character comes in, you use a “current state” variable to track how much of the desired keyword has been “seen”. Initally, NONE of the keyword has been seen. When you receive the first character of the keyword, you increment the state variable. If the next character is the second character of the keyword, you increment the state variable again, etc. If you receive a character that is not the correct nth character of the keyword, you reset the state variable to NONE, and start watching for the first character again.
This approach requires no buffering, and it handles each character exactly once, instead of storing the char in a buffer and doing a string compare “later” (C string, not
In addition to recognizing the keyword, the same approach can be used to parse the value as it is received. Start your value at zero, and as digits are received, multiply the value by ten and add the new digit. When you finally receive the delimiter (a comma, space, NL, whatever), the value is “completed”.
That’s a lot of words for what is much easier to visualize as a bubble graph, perhaps something like this:
Each bubble is a state, and certain characters change the state and “step” to another bubble (i.e., a state change). That chart is from this thread,. Two other threads here and here (with a class to help).
The structure of this problem can seem “upside-down” from the typical approach. Instead of saving a bunch of characters (e.g., a line, page, or message) and working on them later (e.g., searching for keywords, delimiters and digits), you deal with each character immediately. This requires a state variable to remember what you’ve interpreted so far. It may also require holding on to “values” that are not fully computed until a delimiter is seen.