I am trying to grab all substrings in between or after the occurrences of a certain character. Specifically with for search query urls (grabbing the options), for example if I have:
std::string url = "https://www.google.com/search?q=i+need+help&rlz=1C1CHBF_enUS851US851&oq=i+need+help&aqs=chrome.0.69i59j0l3j69i60l2.4646j0j7&sourceid=chrome&ie=UTF-8"
I need to output the strings in between and after (for the last occurrence) the "&" character so the output would be:
rlz=1C1CHBF_enUS851US851
oq=i+need+help
aqs=chrome.0.69i59j0l3j69i60l2.4646j0j7
sourceid=chrome
ie=UTF-8
I understand how to do this with one string, but I am stuck trying to implement it into a loop. This has to be done with several urls of different lengths and number of options.
So far I can only grab one substring, between the first and second occurrences of character, but I need to grab all of them in any given url.
int a = url.find("&") + 1;
int b = url.find("&", url.find("&") + 1);
int c = (b - a);
std::string option = url.substr(a, c);