find_last_of

Discussion in 'C++' started by Mike, Sep 8, 2010.

  1. Mike

    Mike Guest

    Hi
    I need this not only for Win/Lin but also for Mac. So it's fine for /
    and \ within paths but how should I add the old : which were used once
    for mac paths?
    Many thanks
    Michael

    string Texstr = filepath;
    string::size_type n = Texstr.find_last_of("/\\\:");
    Mike, Sep 8, 2010
    #1
    1. Advertising

  2. Mike <>, on 08/09/2010 00:27:26, wrote:

    > Hi
    > I need this not only for Win/Lin but also for Mac. So it's fine for /
    > and \ within paths but how should I add the old : which were used once
    > for mac paths?
    > Many thanks
    > Michael
    >
    > string Texstr = filepath;
    > string::size_type n = Texstr.find_last_of("/\\\:");


    Listen to your compiler when you'll feed that exact last line of code to
    it because of the unknown escape sequence. Anyway, you should be fine
    finding the last colon in a string that way. Though, I have no idea of
    what old mac paths looked like :)

    --
    FSC - http://userscripts.org/scripts/show/59948
    http://fscode.altervista.org - http://sardinias.com
    Francesco S. Carta, Sep 8, 2010
    #2
    1. Advertising

  3. Mike

    Jorgen Grahn Guest

    On Wed, 2010-09-08, Mike wrote:
    > Hi
    > I need this not only for Win/Lin but also for Mac. So it's fine for /
    > and \ within paths but how should I add the old : which were used once
    > for mac paths?
    > Many thanks
    > Michael
    >
    > string Texstr = filepath;
    > string::size_type n = Texstr.find_last_of("/\\\:");


    Why do you escape the ':'? Remove the first two characters, and the
    string reads "\:".

    Note that I know nothing about what you *really* want to do.
    It seems similar to Unix's basename(1), but I don't know what
    you want to happen to C:foo or C:\foo, or /usr//bin or /usr/bin////,
    or /tmp/: and if you want different answers on different OSes.

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
    Jorgen Grahn, Sep 8, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page