Easy but weird

Posted on 2004-11-11
Last Modified: 2010-04-01
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?
Question by:b_vishwajit
    LVL 55

    Expert Comment

    by:Jaime Olivares
    Try with this:
         // test string  
         ip = " 10/02/2004";
        size_t pos=ip.find_first_of(' ') +1;
       procStr=ip.substr(pos, ip.find_last_of(' ')-pos);

        cout << procStr << endl;
    LVL 55

    Accepted Solution

    You have to notices that second argument of substr() is not a position, but a character count.

    Good luck,
    LVL 5

    Author Comment

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now