Strip unknown range of characters between first "/" and second "/"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

    Strip unknown range of characters between first "/" and second "/"

    Could some help m figure out to strip an unknown range of characters in a
    path between the first "/" and "/" found in a folder path somewhere on my
    site.

    eg: /catamaranco/sales/boat/1.asp
    eg: /esserman/newseltter/2004/03/
    eg: /yachtservices/excel/reports/

    I wish to return only:

    "catamaranc o"
    or
    "esserman"
    or
    "yachtservi ces"

    Thanks for advice...
    Jason



  • Aaron [SQL Server MVP]

    #2
    Re: Strip unknown range of characters between first "/" and second "/"

    <%
    function stripStuff(str)
    stripStuff = str
    if instr(str, "/") <> instrRev(str, "/") then
    strs = split(str, "/")
    stripStuff = strs(1)
    end if
    end function

    response.write "<br>" & stripStuff("/catamaranco/sales/boat/1.asp")
    response.write "<br>" & stripStuff("/esserman/newseltter/2004/03/")
    response.write "<br>" & stripStuff("/yachtservices/excel/reports/")
    %>

    --
    Please contact this domain's administrator as their DNS Made Easy services have expired.

    (Reverse address to reply.)




    <jason@catamara nco.com> wrote in message
    news:#0tQWCuhEH A.1356@TK2MSFTN GP09.phx.gbl...[color=blue]
    > Could some help m figure out to strip an unknown range of characters in a
    > path between the first "/" and "/" found in a folder path somewhere on my
    > site.
    >
    > eg: /catamaranco/sales/boat/1.asp
    > eg: /esserman/newseltter/2004/03/
    > eg: /yachtservices/excel/reports/
    >
    > I wish to return only:
    >
    > "catamaranc o"
    > or
    > "esserman"
    > or
    > "yachtservi ces"
    >
    > Thanks for advice...
    > Jason
    >
    >
    >[/color]


    Comment

    • Guest's Avatar

      #3
      Re: Strip unknown range of characters between first &quot;/&quot; and second &quot;/&quot;

      Many thanks - works perfectly!

      "Aaron [SQL Server MVP]" <ten.xoc@dnartr eb.noraa> wrote in message
      news:uUx0hHuhEH A.3832@TK2MSFTN GP10.phx.gbl...[color=blue]
      > <%
      > function stripStuff(str)
      > stripStuff = str
      > if instr(str, "/") <> instrRev(str, "/") then
      > strs = split(str, "/")
      > stripStuff = strs(1)
      > end if
      > end function
      >
      > response.write "<br>" & stripStuff("/catamaranco/sales/boat/1.asp")
      > response.write "<br>" & stripStuff("/esserman/newseltter/2004/03/")
      > response.write "<br>" & stripStuff("/yachtservices/excel/reports/")
      > %>
      >
      > --
      > http://www.aspfaq.com/
      > (Reverse address to reply.)
      >
      >
      >
      >
      > <jason@catamara nco.com> wrote in message
      > news:#0tQWCuhEH A.1356@TK2MSFTN GP09.phx.gbl...[color=green]
      > > Could some help m figure out to strip an unknown range of characters in[/color][/color]
      a[color=blue][color=green]
      > > path between the first "/" and "/" found in a folder path somewhere on[/color][/color]
      my[color=blue][color=green]
      > > site.
      > >
      > > eg: /catamaranco/sales/boat/1.asp
      > > eg: /esserman/newseltter/2004/03/
      > > eg: /yachtservices/excel/reports/
      > >
      > > I wish to return only:
      > >
      > > "catamaranc o"
      > > or
      > > "esserman"
      > > or
      > > "yachtservi ces"
      > >
      > > Thanks for advice...
      > > Jason
      > >
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • Guest's Avatar

        #4
        Re: Strip unknown range of characters between first &quot;/&quot; and second &quot;/&quot;

        Umm :) sorry Aaron, I ran into an added problem after extracting the
        string...how I would then also pull out the remaiing 'stuff' and stuff that
        into a variable?.

        Extract: "/sales/boat/1.asp"

        x= "/catamaranco/sales/boat/1.asp"

        As my ultimate goal is concententation :

        "www". & stripStuff("/catamaranco/sales/boat/1.asp") & ".com" & "/" &
        stripTrailingSt uff(X)

        Result: www.catamaranco .com/sales/boat/1.asp"


        <jason@catamara nco.com> wrote in message
        news:%23DxsxOuh EHA.3632@TK2MSF TNGP09.phx.gbl. ..[color=blue]
        > Many thanks - works perfectly!
        >
        > "Aaron [SQL Server MVP]" <ten.xoc@dnartr eb.noraa> wrote in message
        > news:uUx0hHuhEH A.3832@TK2MSFTN GP10.phx.gbl...[color=green]
        > > <%
        > > function stripStuff(str)
        > > stripStuff = str
        > > if instr(str, "/") <> instrRev(str, "/") then
        > > strs = split(str, "/")
        > > stripStuff = strs(1)
        > > end if
        > > end function
        > >
        > > response.write "<br>" & stripStuff("/catamaranco/sales/boat/1.asp")
        > > response.write "<br>" & stripStuff("/esserman/newseltter/2004/03/")
        > > response.write "<br>" & stripStuff("/yachtservices/excel/reports/")
        > > %>
        > >
        > > --
        > > http://www.aspfaq.com/
        > > (Reverse address to reply.)
        > >
        > >
        > >
        > >
        > > <jason@catamara nco.com> wrote in message
        > > news:#0tQWCuhEH A.1356@TK2MSFTN GP09.phx.gbl...[color=darkred]
        > > > Could some help m figure out to strip an unknown range of characters[/color][/color][/color]
        in[color=blue]
        > a[color=green][color=darkred]
        > > > path between the first "/" and "/" found in a folder path somewhere on[/color][/color]
        > my[color=green][color=darkred]
        > > > site.
        > > >
        > > > eg: /catamaranco/sales/boat/1.asp
        > > > eg: /esserman/newseltter/2004/03/
        > > > eg: /yachtservices/excel/reports/
        > > >
        > > > I wish to return only:
        > > >
        > > > "catamaranc o"
        > > > or
        > > > "esserman"
        > > > or
        > > > "yachtservi ces"
        > > >
        > > > Thanks for advice...
        > > > Jason
        > > >
        > > >
        > > >[/color]
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Guest's Avatar

          #5
          Re: Strip unknown range of characters between first &quot;/&quot; and second &quot;/&quot;

          Ok, I did come up with my own solution...but it seems to waste far too many
          lines of code...could you tell me if there is a better way to write this:

          u_CurrentURL="/catamaranco/sales/boat/1.asp"

          function stripParentDire ctory(str)
          stripParentDire ctory = str
          if instr(str, "/") <> instrRev(str, "/") then

          strs = split(str, "/")
          stripParentDire ctory = strs(1)

          end if
          end function

          ParentDir= stripParentDire ctory(u_Current URL)

          Call SubDirPath(Pare ntDir, u_CurrentURL)


          Sub SubDirPath(Pare ntDir, u_CurrentURL)

          strLen = len(u_CurrentUR L)
          response.write "<br><br>To tal String Length:" & strLen &
          "<br><br>"
          ParDirLen=len(P arentDir) + 2 '//add slash x 2
          response.write "<br><br>Pa rent Dir Length:" & ParDirLen &
          "<br><br>"
          SubPathLen= strLen - ParDirLen
          response.write "<br><br>SubPat h Length:" & SubPathLen &
          "<br><br>"
          Response.write SubPathLen

          MyString= Right(u_Current URL,SubPathLen)
          response.write "<BR><BR>ht tp://www." & ParentDir & ".com/" &
          MyString

          End Sub

          Result: http://www.catamaranco.com/sales/boat/1.asp


          Comment

          • Guest's Avatar

            #6
            Re: Strip unknown range of characters between first &quot;/&quot; and second &quot;/&quot;

            I readpated the script with an extra function which seems to work....is this
            more elegant
            <%
            u_CurrentURL="/catamaranco/sales/boat/1.asp"


            function stripParentDire ctory(str)
            stripParentDire ctory = str
            if instr(str, "/") <> instrRev(str, "/") then
            strs = split(str, "/")
            stripParentDire ctory = strs(1)
            end if
            end function


            Function stripSubPath(Pa rentDir, u_CurrentURL)

            strLen = len(u_CurrentUR L)
            '//response.write "<br><br>To tal String Length:" & strLen &
            "<br><br>"
            ParDirLen=len(P arentDir) + 2 '//add slash x 2
            '//response.write "<br><br>Pa rent Dir Length:" & ParDirLen &
            "<br><br>"

            SubPathLen= strLen - ParDirLen
            '//response.write "<br><br>SubPat h Length:" & SubPathLen & "<br><br>"
            '//Response.write SubPathLen

            MyString= Right(u_Current URL,SubPathLen)
            MyString ="http://www." & ParentDir & ".com/" & MyString

            stripSubPath =MyString

            End Function


            ParentDir= stripParentDire ctory(u_Current URL)
            Response.write stripSubPath(Pa rentDir, u_CurrentURL)

            %>


            Comment

            • Chris Hohmann

              #7
              Re: Strip unknown range of characters between first &quot;/&quot; and second &quot;/&quot;

              <jason@catamara nco.com> wrote in message
              news:OQn0ekuhEH A.3428@TK2MSFTN GP11.phx.gbl...[color=blue]
              > Umm :) sorry Aaron, I ran into an added problem after extracting the
              > string...how I would then also pull out the remaiing 'stuff' and stuff[/color]
              that[color=blue]
              > into a variable?.
              >
              > Extract: "/sales/boat/1.asp"
              >
              > x= "/catamaranco/sales/boat/1.asp"
              >
              > As my ultimate goal is concententation :
              >
              > "www". & stripStuff("/catamaranco/sales/boat/1.asp") & ".com" & "/" &
              > stripTrailingSt uff(X)
              >
              > Result: www.catamaranco .com/sales/boat/1.asp"[/color]

              <script language="JavaS cript" runat="SERVER">
              var s = "/catamaranco/sales/boat/1.asp";
              Response.Write( s.replace(/^\/([^\/]*)/,"www.$1.com")) ;
              </script>
              <br>
              <script language="VBScr ipt" runat="SERVER">
              Dim re : Set re = New RegExp
              With re
              .Pattern = "^/([^/]*)"
              .Global = True
              Response.Write .Replace(s,"www .$1.com")
              End With
              </script>


              Comment

              • Evertjan.

                #8
                Re: Strip unknown range of characters between first &quot;/&quot; and second &quot;/&quot;

                Chris Hohmann wrote on 21 aug 2004 in
                microsoft.publi c.inetserver.as p.general:
                [color=blue]
                > <script language="JavaS cript" runat="SERVER">
                > var s = "/catamaranco/sales/boat/1.asp";
                > Response.Write( s.replace(/^\/([^\/]*)/,"www.$1.com")) ;
                > </script>[/color]

                Response.write(
                [case]
                [color=blue]
                > <br>
                > <script language="VBScr ipt" runat="SERVER">
                > Dim re : Set re = New RegExp
                > With re
                > .Pattern = "^/([^/]*)"
                > .Global = True[/color]

                [Global is not effective with ^ as start of string,
                anyway global=true is not what you want here.]
                [color=blue]
                > Response.Write .Replace(s,"www .$1.com")
                > End With
                > </script>
                >[/color]

                [If the default <%%> language is jscript the order will be reversed,
                so s will not be defined yet for the vbscript part, IMHO & not tested;-)]

                --
                Evertjan.
                The Netherlands.
                (Please change the x'es to dots in my emailaddress)

                Comment

                • Chris Hohmann

                  #9
                  Re: Strip unknown range of characters between first &quot;/&quot; and second &quot;/&quot;


                  "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
                  news:Xns954C608 8EF889eejj99@19 4.109.133.29...[color=blue]
                  > Chris Hohmann wrote on 21 aug 2004 in
                  > microsoft.publi c.inetserver.as p.general:
                  >[color=green]
                  > > <script language="JavaS cript" runat="SERVER">
                  > > var s = "/catamaranco/sales/boat/1.asp";
                  > > Response.Write( s.replace(/^\/([^\/]*)/,"www.$1.com")) ;
                  > > </script>[/color]
                  >
                  > Response.write(
                  > [case][/color]

                  I'm not sure what this means.

                  [color=blue][color=green]
                  > > <br>
                  > > <script language="VBScr ipt" runat="SERVER">
                  > > Dim re : Set re = New RegExp
                  > > With re
                  > > .Pattern = "^/([^/]*)"
                  > > .Global = True[/color]
                  >
                  > [Global is not effective with ^ as start of string,
                  > anyway global=true is not what you want here.]
                  >[/color]
                  You're correct. My intention was to set Global to false. That's what I get
                  for sutting and pasting. However, there are cases when searching on "^"
                  while having global set to true is useful, ie. when multiline is turned on.
                  [color=blue][color=green]
                  > > Response.Write .Replace(s,"www .$1.com")
                  > > End With
                  > > </script>
                  > >[/color]
                  >
                  > [If the default <%%> language is jscript the order will be reversed,
                  > so s will not be defined yet for the vbscript part, IMHO & not tested;-)][/color]

                  Yes, although in this particular circumstance it was more of a "one or the
                  other" scenario, not both.


                  Comment

                  • Evertjan.

                    #10
                    Re: Strip unknown range of characters between first &quot;/&quot; and second &quot;/&quot;

                    Chris Hohmann wrote on 23 aug 2004 in
                    microsoft.publi c.inetserver.as p.general:
                    [color=blue][color=green][color=darkred]
                    >> > <script language="JavaS cript" runat="SERVER">
                    >> > var s = "/catamaranco/sales/boat/1.asp";
                    >> > Response.Write( s.replace(/^\/([^\/]*)/,"www.$1.com")) ;
                    >> > </script>[/color]
                    >>
                    >> Response.write(
                    >> [case][/color]
                    >
                    > I'm not sure what this means.[/color]

                    See the difference!

                    ..write should be lower case in javascript

                    --
                    Evertjan.
                    The Netherlands.
                    (Please change the x'es to dots in my emailaddress)

                    Comment

                    • Chris Hohmann

                      #11
                      Re: Strip unknown range of characters between first &quot;/&quot; and second &quot;/&quot;

                      "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
                      news:Xns954EC69 89F6F6eejj99@19 4.109.133.29...[color=blue]
                      > Chris Hohmann wrote on 23 aug 2004 in
                      > microsoft.publi c.inetserver.as p.general:
                      >[color=green][color=darkred]
                      > >> > <script language="JavaS cript" runat="SERVER">
                      > >> > var s = "/catamaranco/sales/boat/1.asp";
                      > >> > Response.Write( s.replace(/^\/([^\/]*)/,"www.$1.com")) ;
                      > >> > </script>
                      > >>
                      > >> Response.write(
                      > >> [case][/color]
                      > >
                      > > I'm not sure what this means.[/color]
                      >
                      > See the difference!
                      >
                      > .write should be lower case in javascript[/color]

                      Response is a built-in ASP object. As such the names of its
                      methods/members/properties are independent of the scripting language. Here's
                      the documentation on the Response.Write method, listing it with a capital
                      "W":




                      Comment

                      • Evertjan.

                        #12
                        Re: Strip unknown range of characters between first &quot;/&quot; and second &quot;/&quot;

                        Chris Hohmann wrote on 23 aug 2004 in
                        microsoft.publi c.inetserver.as p.general:[color=blue]
                        > "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
                        > news:Xns954EC69 89F6F6eejj99@19 4.109.133.29...[color=green]
                        >> Chris Hohmann wrote on 23 aug 2004 in
                        >> microsoft.publi c.inetserver.as p.general:
                        >>[color=darkred]
                        >> >> > <script language="JavaS cript" runat="SERVER">
                        >> >> > var s = "/catamaranco/sales/boat/1.asp";
                        >> >> > Response.Write( s.replace(/^\/([^\/]*)/,"www.$1.com")) ;
                        >> >> > </script>
                        >> >>
                        >> >> Response.write(
                        >> >> [case]
                        >> >
                        >> > I'm not sure what this means.[/color]
                        >>
                        >> See the difference!
                        >>
                        >> .write should be lower case in javascript[/color]
                        >
                        > Response is a built-in ASP object. As such the names of its
                        > methods/members/properties are independent of the scripting language.[/color]

                        I didn't know that, Chris, silly me. ;-)
                        [color=blue]
                        > Here's the documentation on the Response.Write method, listing it with
                        > a capital "W":
                        > http://www.msdn.microsoft.com/librar...f_vbom_resomwr
                        > ite.asp[/color]

                        --
                        Evertjan.
                        The Netherlands.
                        (Please change the x'es to dots in my emailaddress)

                        Comment

                        • Dave Anderson

                          #13
                          Re: Strip unknown range of characters between first &quot;/&quot; and second &quot;/&quot;

                          Evertjan. wrote:[color=blue][color=green][color=darkred]
                          >>>
                          >>> Response.write(
                          >>> [case][/color]
                          >>
                          >> I'm not sure what this means.[/color]
                          >
                          > See the difference!
                          >
                          > .write should be lower case in javascript[/color]

                          I don't know about javascript, but if this suddenly became true in JScript,
                          I would have a lot of work to do....


                          --
                          Dave Anderson

                          Unsolicited commercial email will be read at a cost of $500 per message. Use
                          of this email address implies consent to these terms. Please do not contact
                          me directly or ask me to contact you directly for assistance. If your
                          question is worth asking, it's worth posting.


                          Comment

                          • Evertjan.

                            #14
                            Re: Strip unknown range of characters between first &quot;/&quot; and second &quot;/&quot;

                            Dave Anderson wrote on 23 aug 2004 in
                            microsoft.publi c.inetserver.as p.general:
                            [color=blue][color=green]
                            >> .write should be lower case in javascript[/color]
                            >
                            > I don't know about javascript, but if this suddenly became true in
                            > JScript, I would have a lot of work to do....[/color]

                            as I was told, Response.Write is not a part of the language, but of a
                            server object that is caseinsensitive , so

                            ResPOnse.wrITE( 'Hi') should be valid.

                            =============

                            However jscript in IE is not so forgiving with document.write:

                            <script type="text/jscript">
                            document.Write( 'Hi')
                            </script>

                            gives an error!

                            --
                            Evertjan.
                            The Netherlands.
                            (Please change the x'es to dots in my emailaddress)

                            Comment

                            • Dave Anderson

                              #15
                              Re: Strip unknown range of characters between first &quot;/&quot; and second &quot;/&quot;

                              "Evertjan." wrote:[color=blue]
                              >
                              > as I was told, Response.Write is not a part of the language,
                              > but of a server object that is caseinsensitive , so
                              >
                              > ResPOnse.wrITE( 'Hi') should be valid.[/color]

                              No, that's not what you were told. The Response object does not require case
                              sensitivity for accessing its properties and methods, but the Response
                              object still must be found in the global namespace, and accordingly must be
                              spelled exactly "Response":

                              Microsoft JScript runtime error '800a1391'
                              'ResPOnse' is undefined


                              If you had spent 5 seconds testing either of your assertions, you may have
                              seen that for yourself.


                              --
                              Dave Anderson

                              Unsolicited commercial email will be read at a cost of $500 per message. Use
                              of this email address implies consent to these terms. Please do not contact
                              me directly or ask me to contact you directly for assistance. If your
                              question is worth asking, it's worth posting.


                              Comment

                              Working...