Get a specific word from a line

Jul 6, 2015 at 10:52am
Hi there i need some help extracting a specific word that is in quotes from a line.

example: <P id="3" name="starting code" entry="1"></P>

i need to extract the name "starting code"(without quotes) and number 1 in (entry="1").

Thanks.
Jul 6, 2015 at 11:22am
Are parameters in exact same order and there is no spaces between name and actual value? If so, you can just use string search methods. Otherwise you would better apply regex to it.
Jul 6, 2015 at 11:26am
You have the line in a std::string.
You can find() the position of name=" .
You can find() the position of next '"'.
Between there is the substr() that you want.

Repeat the procedure for entry=" .
Jul 7, 2015 at 7:48am
You can directly search for starting code in the string and create a substring from the position,
Jul 7, 2015 at 9:30pm
If that's an XML fragment, then another possibility is to use a parser like RapidXML.
http://rapidxml.sourceforge.net/

Andy
Jul 8, 2015 at 8:53pm
Thanks will try use find()
Topic archived. No new replies allowed.