Better way to extract data from string

In a C socket program I have created I need to extract data from a string sent from the Windows client. A small example of the string is:-
SRC=”<Terminalname>” DST=”<CISTERMINALNAME>” EXC=”PICOENQ”

What I need to do is use the "field" to the left of the = to identify the variable name and the "field" to the right of the = , ignoring the leading "< and the trailing >" as the value for the aforementioned variable. eg the variable dst to contain the value, the name of the terminal. char *dst="terminalname".

So far my thinking is to use strtok to cycle thru the string using the = as the token. Then look for the space character preceding the left most "field" and strcmp that to names of predefined variables and when one is found extract the value from the right "field" by maybe finding the 1st >" after it and copy that data to aforementioned variable.

Surely there is a better way to do this.
i would construct an std::string object from it, and then you can do one of two things: use string::find to generate a substring or just lex through the whole string character by character until you find what you are looking for
Topic archived. No new replies allowed.