String manipulation of a URL - strip preceding characters?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jason

    String manipulation of a URL - strip preceding characters?

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



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

    "Riverbend"

    Many thanks

    Jason



  • Aaron Bertrand - MVP

    #2
    Re: String manipulation of a URL - strip preceding characters?

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



    "jason" <jason@catamara nco.com> wrote in message
    news:OYASKvSUDH A.1724@TK2MSFTN GP10.phx.gbl...[color=blue]
    > How would I strip out everything from before the last "/" in the following
    > string generated from request.serverv araibles method:
    >
    > http://www.essermanyachtsales.com/riverbend/
    >
    > ...so that I was just left with:
    >
    > "Riverbend"
    >
    > Many thanks
    >
    > Jason
    >
    >
    >[/color]


    Comment

    • Bob Barrows

      #3
      Re: String manipulation of a URL - strip preceding characters?

      jason wrote:[color=blue]
      > How would I strip out everything from before the last "/" in the
      > following string generated from request.serverv araibles method:
      >
      > http://www.essermanyachtsales.com/riverbend/
      >
      > ...so that I was just left with:
      >
      > "Riverbend"
      >
      > Many thanks
      >
      > Jason[/color]
      This particular string is easy:

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

      However, who is to say that your string might not contain
      "http://www.essermanyac htsales.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


      Comment

      • Bob Barrows

        #4
        Re: String manipulation of a URL - strip preceding characters?

        Aaron Bertrand - MVP wrote:[color=blue][color=green]
        >> However, who is to say that your string might not contain
        >> "http://www.essermanyac htsales.com/riverbend/default.asp"?
        >> Now, you would have to do this:
        >> ar = split(str,"/")
        >> response.write ar(ubound(ar)-1)[/color]
        >
        > Except what if it is
        > "http://www.essermanyac htsales.com/riverbend/subfolder/default.asp"?
        >
        > This is where using ar(3) would always get the base subfolder...[/color]

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

        Bob


        Comment

        • Aaron Bertrand - MVP

          #5
          Re: String manipulation of a URL - strip preceding characters?

          > > This is where using ar(3) would always get the base subfolder...[color=blue]
          >
          > True - depends on what he wants. He DID say " ... everything from before[/color]
          the[color=blue]
          > last "/" ..."[/color]

          Right, which is why I didn't say, "you should use ar(3) instead." :-)


          Comment

          • jason

            #6
            Re: String manipulation of a URL - strip preceding characters?

            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" <aaron@TRASHasp faq.com> wrote in message
            news:ecHtFKTUDH A.3700@tk2msftn gp13.phx.gbl...[color=blue][color=green][color=darkred]
            > > > This is where using ar(3) would always get the base subfolder...[/color]
            > >
            > > True - depends on what he wants. He DID say " ... everything from before[/color]
            > the[color=green]
            > > last "/" ..."[/color]
            >
            > Right, which is why I didn't say, "you should use ar(3) instead." :-)
            >
            >[/color]


            Comment

            • jason

              #7
              Re: String manipulation of a URL - strip preceding characters?

              Thanks


              "Bob Barrows" <reb_01501@yaho o.com> wrote in message
              news:O7cT8FTUDH A.2420@TK2MSFTN GP10.phx.gbl...[color=blue]
              > Aaron Bertrand - MVP wrote:[color=green][color=darkred]
              > >> However, who is to say that your string might not contain
              > >> "http://www.essermanyac htsales.com/riverbend/default.asp"?
              > >> Now, you would have to do this:
              > >> ar = split(str,"/")
              > >> response.write ar(ubound(ar)-1)[/color]
              > >
              > > Except what if it is
              > > "http://www.essermanyac htsales.com/riverbend/subfolder/default.asp"?
              > >
              > > This is where using ar(3) would always get the base subfolder...[/color]
              >
              > True - depends on what he wants. He DID say " ... everything from before[/color]
              the[color=blue]
              > last "/" ..."
              >
              > Bob
              >
              >[/color]


              Comment

              • jason

                #8
                Re: String manipulation of a URL - strip preceding characters?

                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" <aaron@TRASHasp faq.com> wrote in message
                news:ecHtFKTUDH A.3700@tk2msftn gp13.phx.gbl...[color=blue][color=green][color=darkred]
                > > > This is where using ar(3) would always get the base subfolder...[/color]
                > >
                > > True - depends on what he wants. He DID say " ... everything from before[/color]
                > the[color=green]
                > > last "/" ..."[/color]
                >
                > Right, which is why I didn't say, "you should use ar(3) instead." :-)
                >
                >[/color]


                Comment

                Working...