I have been trying to get substrings in a XML tag.
The string: "<Fruits Type="Apple" Quantity="10"></Fruits>"
,
I want only substring1 = Apple substring2 = 10.
string string1 ="<Fruits Type="Apple" Quantity="10"></Fruits>";
int lPos = string1 .find("\"");
string substring2 = string1.substr(lPos + 1);
string substring1 = substring2.substr(0, substring2.find("\""));
substring2 = substring2.substr(substring2.find("\""), substring2.rfind("\"")- substring2.find("\""));
substring2 = substring2.substr(substring2.rfind("\"")+1);
cout<<substring1 << "\n" << substring2;
The Thing is I'm able to get expected output. But what I want is to know if there is any efficient way other than this method.