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

Discussion in 'ASP General' started by Guest, Aug 20, 2004.

  1. Guest

    Guest Guest

    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:

    "catamaranco"
    or
    "esserman"
    or
    "yachtservices"

    Thanks for advice...
    Jason
     
    Guest, Aug 20, 2004
    #1
    1. Advertising

  2. <%
    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.)




    <> wrote in message
    news:#...
    > 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:
    >
    > "catamaranco"
    > or
    > "esserman"
    > or
    > "yachtservices"
    >
    > Thanks for advice...
    > Jason
    >
    >
    >
     
    Aaron [SQL Server MVP], Aug 20, 2004
    #2
    1. Advertising

  3. Guest

    Guest Guest

    Many thanks - works perfectly!

    "Aaron [SQL Server MVP]" <> wrote in message
    news:...
    > <%
    > 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.)
    >
    >
    >
    >
    > <> wrote in message
    > news:#...
    > > 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:
    > >
    > > "catamaranco"
    > > or
    > > "esserman"
    > > or
    > > "yachtservices"
    > >
    > > Thanks for advice...
    > > Jason
    > >
    > >
    > >

    >
    >
     
    Guest, Aug 20, 2004
    #3
  4. Guest

    Guest Guest

    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" & "/" &
    stripTrailingStuff(X)

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


    <> wrote in message
    news:%...
    > Many thanks - works perfectly!
    >
    > "Aaron [SQL Server MVP]" <> wrote in message
    > news:...
    > > <%
    > > 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.)
    > >
    > >
    > >
    > >
    > > <> wrote in message
    > > news:#...
    > > > 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:
    > > >
    > > > "catamaranco"
    > > > or
    > > > "esserman"
    > > > or
    > > > "yachtservices"
    > > >
    > > > Thanks for advice...
    > > > Jason
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Guest, Aug 20, 2004
    #4
  5. Guest

    Guest Guest

    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 stripParentDirectory(str)
    stripParentDirectory = str
    if instr(str, "/") <> instrRev(str, "/") then

    strs = split(str, "/")
    stripParentDirectory = strs(1)

    end if
    end function

    ParentDir= stripParentDirectory(u_CurrentURL)

    Call SubDirPath(ParentDir, u_CurrentURL)


    Sub SubDirPath(ParentDir, u_CurrentURL)

    strLen = len(u_CurrentURL)
    response.write "<br><br>Total String Length:" & strLen &
    "<br><br>"
    ParDirLen=len(ParentDir) + 2 '//add slash x 2
    response.write "<br><br>Parent Dir Length:" & ParDirLen &
    "<br><br>"
    SubPathLen= strLen - ParDirLen
    response.write "<br><br>SubPath Length:" & SubPathLen &
    "<br><br>"
    Response.write SubPathLen

    MyString= Right(u_CurrentURL,SubPathLen)
    response.write "<BR><BR>http://www." & ParentDir & ".com/" &
    MyString

    End Sub

    Result: http://www.catamaranco.com/sales/boat/1.asp
     
    Guest, Aug 20, 2004
    #5
  6. Guest

    Guest Guest

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


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


    Function stripSubPath(ParentDir, u_CurrentURL)

    strLen = len(u_CurrentURL)
    '//response.write "<br><br>Total String Length:" & strLen &
    "<br><br>"
    ParDirLen=len(ParentDir) + 2 '//add slash x 2
    '//response.write "<br><br>Parent Dir Length:" & ParDirLen &
    "<br><br>"

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

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

    stripSubPath =MyString

    End Function


    ParentDir= stripParentDirectory(u_CurrentURL)
    Response.write stripSubPath(ParentDir, u_CurrentURL)

    %>
     
    Guest, Aug 20, 2004
    #6
  7. <> wrote in message
    news:...
    > 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" & "/" &
    > stripTrailingStuff(X)
    >
    > Result: www.catamaranco.com/sales/boat/1.asp"


    <script language="JavaScript" runat="SERVER">
    var s = "/catamaranco/sales/boat/1.asp";
    Response.Write(s.replace(/^\/([^\/]*)/,"www.$1.com"));
    </script>
    <br>
    <script language="VBScript" runat="SERVER">
    Dim re : Set re = New RegExp
    With re
    .Pattern = "^/([^/]*)"
    .Global = True
    Response.Write .Replace(s,"www.$1.com")
    End With
    </script>
     
    Chris Hohmann, Aug 20, 2004
    #7
  8. Guest

    Evertjan. Guest

    Chris Hohmann wrote on 21 aug 2004 in
    microsoft.public.inetserver.asp.general:

    > <script language="JavaScript" runat="SERVER">
    > var s = "/catamaranco/sales/boat/1.asp";
    > Response.Write(s.replace(/^\/([^\/]*)/,"www.$1.com"));
    > </script>


    Response.write(
    [case]

    > <br>
    > <script language="VBScript" runat="SERVER">
    > Dim re : Set re = New RegExp
    > With re
    > .Pattern = "^/([^/]*)"
    > .Global = True


    [Global is not effective with ^ as start of string,
    anyway global=true is not what you want here.]

    > Response.Write .Replace(s,"www.$1.com")
    > End With
    > </script>
    >


    [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)
     
    Evertjan., Aug 21, 2004
    #8
  9. "Evertjan." <> wrote in message
    news:Xns954C6088EF889eejj99@194.109.133.29...
    > Chris Hohmann wrote on 21 aug 2004 in
    > microsoft.public.inetserver.asp.general:
    >
    > > <script language="JavaScript" 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.


    > > <br>
    > > <script language="VBScript" runat="SERVER">
    > > Dim re : Set re = New RegExp
    > > With re
    > > .Pattern = "^/([^/]*)"
    > > .Global = True

    >
    > [Global is not effective with ^ as start of string,
    > anyway global=true is not what you want here.]
    >

    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.

    > > Response.Write .Replace(s,"www.$1.com")
    > > End With
    > > </script>
    > >

    >
    > [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;-)]


    Yes, although in this particular circumstance it was more of a "one or the
    other" scenario, not both.
     
    Chris Hohmann, Aug 23, 2004
    #9
  10. Guest

    Evertjan. Guest

    Chris Hohmann wrote on 23 aug 2004 in
    microsoft.public.inetserver.asp.general:

    >> > <script language="JavaScript" 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.


    See the difference!

    ..write should be lower case in javascript

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 23, 2004
    #10
  11. Guest

    Evertjan. Guest

    Chris Hohmann wrote on 23 aug 2004 in
    microsoft.public.inetserver.asp.general:
    > "Evertjan." <> wrote in message
    > news:Xns954EC6989F6F6eejj99@194.109.133.29...
    >> Chris Hohmann wrote on 23 aug 2004 in
    >> microsoft.public.inetserver.asp.general:
    >>
    >> >> > <script language="JavaScript" 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.

    >>
    >> See the difference!
    >>
    >> .write should be lower case in javascript

    >
    > Response is a built-in ASP object. As such the names of its
    > methods/members/properties are independent of the scripting language.


    I didn't know that, Chris, silly me. ;-)

    > Here's the documentation on the Response.Write method, listing it with
    > a capital "W":
    > http://www.msdn.microsoft.com/library/en-us/iissdk/iis/ref_vbom_resomwr
    > ite.asp


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 23, 2004
    #11
  12. "Evertjan." <> wrote in message
    news:Xns954EC6989F6F6eejj99@194.109.133.29...
    > Chris Hohmann wrote on 23 aug 2004 in
    > microsoft.public.inetserver.asp.general:
    >
    > >> > <script language="JavaScript" 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.

    >
    > See the difference!
    >
    > .write should be lower case in javascript


    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":

    http://www.msdn.microsoft.com/library/en-us/iissdk/iis/ref_vbom_resomwrite.asp
     
    Chris Hohmann, Aug 23, 2004
    #12
  13. Evertjan. wrote:
    >>>
    >>> Response.write(
    >>> [case]

    >>
    >> I'm not sure what this means.

    >
    > See the difference!
    >
    > .write should be lower case in javascript


    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.
     
    Dave Anderson, Aug 23, 2004
    #13
  14. Guest

    Evertjan. Guest

    Dave Anderson wrote on 23 aug 2004 in
    microsoft.public.inetserver.asp.general:

    >> .write should be lower case in javascript

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


    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)
     
    Evertjan., Aug 23, 2004
    #14
  15. "Evertjan." wrote:
    >
    > 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.


    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.
     
    Dave Anderson, Aug 23, 2004
    #15
  16. Guest

    Evertjan. Guest

    Dave Anderson wrote on 24 aug 2004 in
    microsoft.public.inetserver.asp.general:

    > "Evertjan." wrote:
    >>
    >> 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.

    >
    > 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.


    So now I am. Told that is.

    You were wrong about the 5 seconds, though.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 24, 2004
    #16
  17. Evertjan. wrote:
    >> If you had spent 5 seconds testing either of your assertions,
    >> you may have seen that for yourself.

    >
    > So now I am. Told that is.
    >
    > You were wrong about the 5 seconds, though.


    Fair enough. I suppose the day was getting long and my nerves short. Sorry.


    --
    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.
     
    Dave Anderson, Aug 24, 2004
    #17
    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. sintral
    Replies:
    9
    Views:
    4,347
    Ben Bacarisse
    Dec 7, 2008
  2. Aquila
    Replies:
    35
    Views:
    458
    Mathieu Bouchard
    Mar 31, 2005
  3. Vincent Arnoux
    Replies:
    1
    Views:
    255
    Arnaud Bergeron
    Aug 11, 2006
  4. DB
    Replies:
    5
    Views:
    152
    J├╝rgen Exner
    Jul 17, 2004
  5. yelipolok
    Replies:
    4
    Views:
    270
    John W. Krahn
    Jan 27, 2010
Loading...

Share This Page