Link to home
Start Free TrialLog in
Avatar of b_vishwajit
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.find_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?
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Try with this:
     // 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;
ASKER CERTIFIED SOLUTION
Avatar of Jaime Olivares
Jaime Olivares
Flag of Peru image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of b_vishwajit
b_vishwajit

ASKER

I figured it out. Never mind. I will just award you the points.