Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts

    Replace by tags?

    Hello,
    I'm wondering how I can do a replace on a chunk of html code using tags.

    example, I want to replace the following tag and everything in between.
    <!--start-->
    HTML STUFF
    <!--stop-->


    how can this be done?

    thanks in advance for your time!
    -ken

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    I'd take a look at regular expressions, 4guys has an article on it:
    http://www.4guysfromrolla.com/webtech/120400-1.shtml

    Let us know if you run into any problems.

    Good luck;

  • #3
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    hmm, I've never used regular expressions before, though I know of them.

    I ended up doing this:

    TempStart = InStr(rsPoOutPut("PoHTML"),"<!--start-->")
    TempStop = InStr(rsPoOutPut("PoHTML"),"<!--stop-->")

    StrHTMLTempStart = left(rsPoOutPut("PoHTML"),TempStart)
    StrHTMLTempStop = left(rsPoOutPut("PoHTML"),TempStop)
    StrHTMLCut = replace(rsPoOutPut("PoHTML"),StrHTMLTempStop,"")
    StrHTMLCut = StrHTMLTempStart&""&StrHTMLCut


    do you think this is too messy of a solution? it's working, but seems a little hacked too me.

    thanks again,
    -Ken

  • #4
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    Heres maybe one possiblity with a regex:
    Code:
    <%@ Language=VBScript %>
    <html>
    <head>
    </head>
    <body>
    <%
    
    Dim objReg
    Dim strTest
    Dim objMatches
    
    strTest = "<!--start-->this is some html <!--stop--><br>this is text after tags"
    Response.Write("The string before the regex <br><b>" & strTest & "</b>")
    Set objReg = new RegExp
    objReg.Pattern = "<!--start-->(.*?)<!--stop-->"
    objReg.IgnoreCase = true
    objReg.Global = true
    Set objMatches = objReg.Execute(strTest)
    Response.Write("<br><hr>The string after regex <br><b>" & Replace(strTest, objMatches(0).Value, "Replacement") & "</b>")
    
    %>
    </body>
    </html>
    Let me know how that goes.

    Good luck;


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •