b_vishwajit
asked on
Easy but weird
I have problem extracting a substring from a input. The input consists of ipaddress_url_date where each underscore character indicates a space.
I am using:
>>procStr=ip.substr(ip.fin d_first_of (" "), ip.find_last_of(" "));
to extract url from the input but it does not work and procStr ends up with url_date thought I am just trying to extract url. Whats wrong?
I am using:
>>procStr=ip.substr(ip.fin
to extract url from the input but it does not work and procStr ends up with url_date thought I am just trying to extract url. Whats wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I figured it out. Never mind. I will just award you the points.
// test string
ip = "192.150.15.12 http://www.yoursite.com 10/02/2004";
size_t pos=ip.find_first_of(' ') +1;
procStr=ip.substr(pos, ip.find_last_of(' ')-pos);
cout << procStr << endl;