String manipulation of a URL - strip preceding characters?

Discussion in 'ASP General' started by jason, Jul 23, 2003.

  1. jason

    jason Guest

    How would I strip out everything from before the last "/" in the following
    string generated from request.servervaraibles method:

    http://www.essermanyachtsales.com/riverbend/

    ....so that I was just left with:

    "Riverbend"

    Many thanks

    Jason
     
    jason, Jul 23, 2003
    #1
    1. Advertising

  2. url = "http://www.essermanyachtsales.com/riverbend/"
    url = split(url, "/"): response.write url(3)



    "jason" <> wrote in message
    news:...
    > How would I strip out everything from before the last "/" in the following
    > string generated from request.servervaraibles method:
    >
    > http://www.essermanyachtsales.com/riverbend/
    >
    > ...so that I was just left with:
    >
    > "Riverbend"
    >
    > Many thanks
    >
    > Jason
    >
    >
    >
     
    Aaron Bertrand - MVP, Jul 23, 2003
    #2
    1. Advertising

  3. jason

    Bob Barrows Guest

    jason wrote:
    > How would I strip out everything from before the last "/" in the
    > following string generated from request.servervaraibles method:
    >
    > http://www.essermanyachtsales.com/riverbend/
    >
    > ...so that I was just left with:
    >
    > "Riverbend"
    >
    > Many thanks
    >
    > Jason

    This particular string is easy:

    dim str,ar
    str="http://www.essermanyachtsales.com/riverbend/"
    ar = split(str,"/")
    response.write ar(ubound(ar))

    However, who is to say that your string might not contain
    "http://www.essermanyachtsales.com/riverbend/default.asp"?
    Now, you would have to do this:
    ar = split(str,"/")
    response.write ar(ubound(ar)-1)

    So, use If:

    ar = split(str,"/")
    if right(str,1) = "/" then
    response.write ar(ubound(ar))
    else
    response.write ar(ubound(ar)-1)
    end if

    Of course, you have to check to make sure str contains any characters at all
    ....

    HTH,
    Bob Barrows
     
    Bob Barrows, Jul 23, 2003
    #3
  4. jason

    Bob Barrows Guest

    Aaron Bertrand - MVP wrote:
    >> However, who is to say that your string might not contain
    >> "http://www.essermanyachtsales.com/riverbend/default.asp"?
    >> Now, you would have to do this:
    >> ar = split(str,"/")
    >> response.write ar(ubound(ar)-1)

    >
    > Except what if it is
    > "http://www.essermanyachtsales.com/riverbend/subfolder/default.asp"?
    >
    > This is where using ar(3) would always get the base subfolder...


    True - depends on what he wants. He DID say " ... everything from before the
    last "/" ..."

    Bob
     
    Bob Barrows, Jul 23, 2003
    #4
  5. > > This is where using ar(3) would always get the base subfolder...
    >
    > True - depends on what he wants. He DID say " ... everything from before

    the
    > last "/" ..."


    Right, which is why I didn't say, "you should use ar(3) instead." :)
     
    Aaron Bertrand - MVP, Jul 23, 2003
    #5
  6. jason

    jason Guest

    I guess I should be specific that I cannot always know in advance how many
    subfolders there will be after the url...BUT...I always need to know what is
    the LAST subfolder and its content...

    Does this make sense....

    Does ar(3) still work is it fixed folder?
    "Aaron Bertrand - MVP" <> wrote in message
    news:...
    > > > This is where using ar(3) would always get the base subfolder...

    > >
    > > True - depends on what he wants. He DID say " ... everything from before

    > the
    > > last "/" ..."

    >
    > Right, which is why I didn't say, "you should use ar(3) instead." :)
    >
    >
     
    jason, Jul 23, 2003
    #6
  7. jason

    jason Guest

    Thanks


    "Bob Barrows" <> wrote in message
    news:...
    > Aaron Bertrand - MVP wrote:
    > >> However, who is to say that your string might not contain
    > >> "http://www.essermanyachtsales.com/riverbend/default.asp"?
    > >> Now, you would have to do this:
    > >> ar = split(str,"/")
    > >> response.write ar(ubound(ar)-1)

    > >
    > > Except what if it is
    > > "http://www.essermanyachtsales.com/riverbend/subfolder/default.asp"?
    > >
    > > This is where using ar(3) would always get the base subfolder...

    >
    > True - depends on what he wants. He DID say " ... everything from before

    the
    > last "/" ..."
    >
    > Bob
    >
    >
     
    jason, Jul 23, 2003
    #7
  8. jason

    jason Guest

    Thanks - stupid question: What if I always wanted to get the LAST subfolder
    in the url no matter how many subfolders appear in the url....would this
    still work?

    - Jason
    "Aaron Bertrand - MVP" <> wrote in message
    news:...
    > > > This is where using ar(3) would always get the base subfolder...

    > >
    > > True - depends on what he wants. He DID say " ... everything from before

    > the
    > > last "/" ..."

    >
    > Right, which is why I didn't say, "you should use ar(3) instead." :)
    >
    >
     
    jason, Jul 23, 2003
    #8
    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.
Similar Threads
  1. Steve Bergman
    Replies:
    6
    Views:
    404
    Diez B. Roggisch
    Sep 26, 2005
  2. Replies:
    1
    Views:
    688
    Martin Honnen
    Jun 6, 2008
  3. Aquila
    Replies:
    35
    Views:
    484
    Mathieu Bouchard
    Mar 31, 2005
  4. DB
    Replies:
    5
    Views:
    158
    J├╝rgen Exner
    Jul 17, 2004
  5. yelipolok
    Replies:
    4
    Views:
    278
    John W. Krahn
    Jan 27, 2010
Loading...

Share This Page