• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

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?
  • 2
1 Solution
Jaime OlivaresSoftware ArchitectCommented:
Try with this:
     // test string  
     ip = " 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;
Jaime OlivaresSoftware ArchitectCommented:
You have to notices that second argument of substr() is not a position, but a character count.

Good luck,
b_vishwajitAuthor Commented:
I figured it out. Never mind. I will just award you the points.

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now