How to Split HTML String?

Discussion in 'ASP General' started by vunet.us@gmail.com, Feb 7, 2007.

  1. Guest

    Hello,
    I use XMLHTTP to get an HTML of another page. Then, I need to cut some
    middle part of that HTML string but I have problems doing it (see note
    in caps below). The error I have generated at response.write (because
    it does not split) is:

    Microsoft VBScript runtime error '800a0009'
    Subscript out of range: '[number: 1]'
    /get_item.asp, line 55

    Dim objXmlHttp
    Dim strHTML
    Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    objXmlHttp.open "GET", "http://www.site.com/item.asp?id=10, False
    objXmlHttp.send
    strHTML = objXmlHttp.responseText
    Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
    HTMLArr = split(FullHTML,"<!--item code separator-->") 'THIS DOES NOT
    SPLIT
    response.write HTMLArr(1)

    dim PureHTML : PureHTML = FullHTML 'HTMLArr(1)

    Please, suggest.
     
    , Feb 7, 2007
    #1
    1. Advertising

  2. McKirahan Guest

    <> wrote in message
    news:...
    > Hello,
    > I use XMLHTTP to get an HTML of another page. Then, I need to cut some
    > middle part of that HTML string but I have problems doing it (see note
    > in caps below). The error I have generated at response.write (because
    > it does not split) is:
    >
    > Microsoft VBScript runtime error '800a0009'
    > Subscript out of range: '[number: 1]'
    > /get_item.asp, line 55
    >
    > Dim objXmlHttp
    > Dim strHTML
    > Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    > objXmlHttp.open "GET", "http://www.site.com/item.asp?id=10, False
    > objXmlHttp.send
    > strHTML = objXmlHttp.responseText
    > Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
    > HTMLArr = split(FullHTML,"<!--item code separator-->") 'THIS DOES NOT
    > SPLIT
    > response.write HTMLArr(1)
    >
    > dim PureHTML : PureHTML = FullHTML 'HTMLArr(1)




    Are you trying to split on a string?
    Your example shows this:
    "<!--item code separator-->"

    The delimiter in Split() is only one character?

    Syntax
    Split(expression[, delimiter[, count[, compare]]])
    expression -- Required.
    delimiter -- Optional.
    String character used to identify substring limits.
    If omitted, the space character (" ") is assumed to be the
    delimiter.

    If not then post an example of the string that needs to be split
    along with your Split() statement.

    How the string is retrieved (as long as it exists) doesn't matter.
     
    McKirahan, Feb 7, 2007
    #2
    1. Advertising

  3. Evertjan. Guest

    wrote on 07 feb 2007 in microsoft.public.inetserver.asp.general:

    > Hello,
    > I use XMLHTTP to get an HTML of another page. Then, I need to cut some
    > middle part of that HTML string but I have problems doing it (see note
    > in caps below). The error I have generated at response.write (because
    > it does not split) is:
    >
    > Microsoft VBScript runtime error '800a0009'
    > Subscript out of range: '[number: 1]'
    > /get_item.asp, line 55
    >
    > Dim objXmlHttp
    > Dim strHTML
    > Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    > objXmlHttp.open "GET", "http://www.site.com/item.asp?id=10, False
    > objXmlHttp.send
    > strHTML = objXmlHttp.responseText
    > Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
    > HTMLArr = split(FullHTML,"<!--item code separator-->")
    > 'THIS DOES NOT SPLIT
    > response.write HTMLArr(1)


    It should work, test by trial and error:

    <script type='text/vbscript'>

    a = "aaa<!--item code separator-->bbb"
    b = split(a,"<!--item code separator-->")
    alert(b(0)) '' aaa
    alert(b(1)) '' bbb

    </script>

    I suspect the string FullHTML does not contain the search string.

    Test by:

    response.write HTMLArr(0) & "<br>"
    response.write HTMLArr(1)

    or by:

    <script type='text/vbscript'>

    a = "aaa<!--item code separator-->bbb"
    b = split(a,"<!--item code xxxxxx separator-->")
    alert(b(0)) '' aaa<!--item code separator-->bbb
    alert(b(1)) '' error

    </script>



    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 7, 2007
    #3
  4. <> wrote in message
    news:...
    > Hello,
    > I use XMLHTTP to get an HTML of another page. Then, I need to cut some
    > middle part of that HTML string but I have problems doing it (see note
    > in caps below). The error I have generated at response.write (because
    > it does not split) is:
    >
    > Microsoft VBScript runtime error '800a0009'
    > Subscript out of range: '[number: 1]'
    > /get_item.asp, line 55
    >
    > Dim objXmlHttp
    > Dim strHTML
    > Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    > objXmlHttp.open "GET", "http://www.site.com/item.asp?id=10, False
    > objXmlHttp.send
    > strHTML = objXmlHttp.responseText
    > Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
    > HTMLArr = split(FullHTML,"<!--item code separator-->") 'THIS DOES NOT
    > SPLIT
    > response.write HTMLArr(1)
    >
    > dim PureHTML : PureHTML = FullHTML 'HTMLArr(1)
    >
    > Please, suggest.
    >


    Evertjan is correct, it should work

    try

    for each thing in HTMLAr
    response.write thing & "<br>"
    next

    thi should show you what your working with
     
    ThatsIT.com.au, Feb 7, 2007
    #4
  5. Guest

    On Feb 7, 6:48 am, "ThatsIT.com.au" <slim@thatsIT> wrote:
    > <> wrote in message
    >
    > news:...
    >
    >
    >
    > > Hello,
    > > I use XMLHTTP to get an HTML of another page. Then, I need to cut some
    > > middle part of that HTML string but I have problems doing it (see note
    > > in caps below). The error I have generated at response.write (because
    > > it does not split) is:

    >
    > > Microsoft VBScript runtime error '800a0009'
    > > Subscript out of range: '[number: 1]'
    > > /get_item.asp, line 55

    >
    > > Dim objXmlHttp
    > > Dim strHTML
    > > Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    > > objXmlHttp.open "GET", "http://www.site.com/item.asp?id=10, False
    > > objXmlHttp.send
    > > strHTML = objXmlHttp.responseText
    > > Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
    > > HTMLArr = split(FullHTML,"<!--item code separator-->") 'THIS DOES NOT
    > > SPLIT
    > > response.write HTMLArr(1)

    >
    > > dim PureHTML : PureHTML = FullHTML 'HTMLArr(1)

    >
    > > Please, suggest.

    >
    > Evertjan is correct, it should work
    >
    > try
    >
    > for each thing in HTMLAr
    > response.write thing & "<br>"
    > next
    >
    > thi should show you what your working with

    Dear experts!
    If this will work:
    dim a, b
    a = "aaa<!--item code separator-->bbb"
    b = split(a,"<!--item code xxxxxx separator-->")
    response.write b(0) '' aaa
    response.write b(1) '' bbb

    this won't:
    Dim objXmlHttp
    Dim strHTML
    Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    objXmlHttp.open "GET", "http://www.site.com/item.asp?id=10,
    False
    objXmlHttp.send
    strHTML = objXmlHttp.responseText
    Dim a: a= Server.HTMLEncode(strHTML)
    b = split(a,"<!--item code separator-->") 'THIS DOES NOT WORK
    response.write b(0) '' aaabbb
    response.write b(1) '' error

    It must be because of the data type or something I suspect? But
    cStr(a) does not help too. Also, there is <!--item code separator-->
    in that code, for sure!
    Thank you all.
     
    , Feb 7, 2007
    #5
  6. Evertjan. Guest

    wrote on 07 feb 2007 in microsoft.public.inetserver.asp.general:

    > On Feb 7, 6:48 am, "ThatsIT.com.au" <slim@thatsIT> wrote:
    >> <> wrote in message

    [..]
    >>
    >> Evertjan is correct, it should work
    >>
    >> try
    >>
    >> for each thing in HTMLAr
    >> response.write thing & "<br>"
    >> next
    >>
    >> thi should show you what your working with

    > Dear experts!
    > If this will work:
    > dim a, b
    > a = "aaa<!--item code separator-->bbb"
    > b = split(a,"<!--item code xxxxxx separator-->")
    > response.write b(0) '' aaa
    > response.write b(1) '' bbb
    >
    > this won't:
    > Dim objXmlHttp
    > Dim strHTML
    > Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    > objXmlHttp.open "GET", "http://www.site.com/item.asp?id=10,
    > False
    > objXmlHttp.send
    > strHTML = objXmlHttp.responseText
    > Dim a: a= Server.HTMLEncode(strHTML)
    > b = split(a,"<!--item code separator-->") 'THIS DOES NOT WORK
    > response.write b(0) '' aaabbb
    > response.write b(1) '' error
    >
    > It must be because of the data type or something I suspect? But
    > cStr(a) does not help too. Also, there is <!--item code separator-->
    > in that code, for sure!
    > Thank you all.


    You are wrong pointing at in the error line,
    because the error text you quoted was:

    >> Microsoft VBScript runtime error '800a0009'
    >> Subscript out of range: '[number: 1]'
    >> /get_item.asp, line 55


    being about a nonexistent subscript,
    it cannot have been the line with the split()
    but it mut have been this line:

    >> response.write HTMLArr(1)


    Conclusion: the split() works OK,
    but there is no HTMLArr(1),
    so the split did not find the string searched for
    and returned an array with only one member.

    QED.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Feb 7, 2007
    #6
  7. wrote:
    > On Feb 7, 6:48 am, "ThatsIT.com.au" <slim@thatsIT> wrote:
    > Dim a: a= Server.HTMLEncode(strHTML)


    Do this:
    Response.Write a

    run the page and view source. Do you see <!--item code separator--> in
    the source?

    Or do you see something like this:
    &lt;!--item code separator--&gt;

    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Feb 7, 2007
    #7
  8. Guest

    On Feb 7, 11:31 am, "Bob Barrows [MVP]" <>
    wrote:
    > wrote:
    > > On Feb 7, 6:48 am, "ThatsIT.com.au" <slim@thatsIT> wrote:
    > > Dim a: a= Server.HTMLEncode(strHTML)

    >
    > Do this:
    > Response.Write a
    >
    > run the page and view source. Do you see <!--item code separator--> in
    > the source?
    >
    > Or do you see something like this:
    > &lt;!--item code separator--&gt;
    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.


    when I do what you say:
    HTMLArr = split(FullHTML,"<!--item code separator-->")
    I only get:
    response.write HTMLArr(0)
    and HTMLArr(0) does contain 2 lines of <!--item code separator-->

    Just copy and paste this code to ASP page to see it not working, if
    you can, and let me know, if possible:
    (not, this is a fake example)

    Dim objXmlHttp
    Dim strHTML
    Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    objXmlHttp.open "GET", "http://devguru.com/technologies/
    javascript/home.asp", False
    objXmlHttp.send
    strHTML = objXmlHttp.responseText
    Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
    HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
    response.write HTMLArr(1)


    Thanks
     
    , Feb 7, 2007
    #8
  9. wrote:
    >
    > when I do what you say:
    > HTMLArr = split(FullHTML,"<!--item code separator-->")
    > I only get:
    > response.write HTMLArr(0)
    > and HTMLArr(0) does contain 2 lines of <!--item code separator-->


    No no no
    response.Write FullHTML. Run the page. View Source. Do you see "<!--item
    code separator-->" or "&lt;!--item code separator--&gt;"?



    >
    > Just copy and paste this code to ASP page to see it not working, if
    > you can, and let me know, if possible:
    > (not, this is a fake example)
    >
    > Dim objXmlHttp
    > Dim strHTML
    > Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    > objXmlHttp.open "GET", "http://devguru.com/technologies/
    > javascript/home.asp", False
    > objXmlHttp.send
    > strHTML = objXmlHttp.responseText
    > Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
    > HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
    > response.write HTMLArr(1)
    >


    OK, I guess I have to lead you by the hand. :)
    After using HTMLEncode, your string no longer contains "<!-- Main
    Content Begins -->". It contains "&lt;!-- Main Content Begins --&gt;", a
    fact which you can ascertain by writing the string to response, running
    the page and viewing source. You either have to do this:

    strHTML = objXmlHttp.responseText
    Dim FullHTML : FullHTML = strHTML
    HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
    response.write Server.HTMLEncode(HTMLArr(1))

    or this:

    strHTML = objXmlHttp.responseText
    Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
    HTMLArr = split(FullHTML,"&lt;!-- Main Content Begins --&gt;")
    response.write HTMLArr(1)




    --
    Microsoft MVP -- ASP/ASP.NET
    Please reply to the newsgroup. The email account listed in my From
    header is my spam trap, so I don't check it very often. You will get a
    quicker response by posting to the newsgroup.
     
    Bob Barrows [MVP], Feb 7, 2007
    #9
  10. Guest

    On Feb 7, 1:26 pm, "Bob Barrows [MVP]" <>
    wrote:
    > wrote:
    >
    > > when I do what you say:
    > > HTMLArr = split(FullHTML,"<!--item code separator-->")
    > > I only get:
    > > response.write HTMLArr(0)
    > > and HTMLArr(0) does contain 2 lines of <!--item code separator-->

    >
    > No no no
    > response.Write FullHTML. Run the page. View Source. Do you see "<!--item
    > code separator-->" or "&lt;!--item code separator--&gt;"?
    >
    >
    >
    >
    >
    > > Just copy and paste this code to ASP page to see it not working, if
    > > you can, and let me know, if possible:
    > > (not, this is a fake example)

    >
    > > Dim objXmlHttp
    > > Dim strHTML
    > > Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    > > objXmlHttp.open "GET", "http://devguru.com/technologies/
    > > javascript/home.asp", False
    > > objXmlHttp.send
    > > strHTML = objXmlHttp.responseText
    > > Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
    > > HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
    > > response.write HTMLArr(1)

    >
    > OK, I guess I have to lead you by the hand. :)
    > After using HTMLEncode, your string no longer contains "<!-- Main
    > Content Begins -->". It contains "&lt;!-- Main Content Begins --&gt;", a
    > fact which you can ascertain by writing the string to response, running
    > the page and viewing source. You either have to do this:
    >
    > strHTML = objXmlHttp.responseText
    > Dim FullHTML : FullHTML = strHTML
    > HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
    > response.write Server.HTMLEncode(HTMLArr(1))
    >
    > or this:
    >
    > strHTML = objXmlHttp.responseText
    > Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
    > HTMLArr = split(FullHTML,"&lt;!-- Main Content Begins --&gt;")
    > response.write HTMLArr(1)
    >
    > --
    > Microsoft MVP -- ASP/ASP.NET
    > Please reply to the newsgroup. The email account listed in my From
    > header is my spam trap, so I don't check it very often. You will get a
    > quicker response by posting to the newsgroup.


    oh, I did not know that <!-- will become &lt;!-- during this
    encoding... Now I see. Allow me to fix this and I will come back here
    with confirmation. Sorry, but within 6 hours from now. Thank you for
    leading me by your hand!
     
    , Feb 7, 2007
    #10
  11. Guest

    On Feb 7, 2:23 pm, wrote:
    > On Feb 7, 1:26 pm, "Bob Barrows [MVP]" <>
    > wrote:
    >
    >
    >
    > > wrote:

    >
    > > > when I do what you say:
    > > > HTMLArr = split(FullHTML,"<!--item code separator-->")
    > > > I only get:
    > > > response.write HTMLArr(0)
    > > > and HTMLArr(0) does contain 2 lines of <!--item code separator-->

    >
    > > No no no
    > > response.Write FullHTML. Run the page. View Source. Do you see "<!--item
    > > code separator-->" or "&lt;!--item code separator--&gt;"?

    >
    > > > Just copy and paste this code to ASP page to see it not working, if
    > > > you can, and let me know, if possible:
    > > > (not, this is a fake example)

    >
    > > > Dim objXmlHttp
    > > > Dim strHTML
    > > > Set objXmlHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    > > > objXmlHttp.open "GET", "http://devguru.com/technologies/
    > > > javascript/home.asp", False
    > > > objXmlHttp.send
    > > > strHTML = objXmlHttp.responseText
    > > > Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
    > > > HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
    > > > response.write HTMLArr(1)

    >
    > > OK, I guess I have to lead you by the hand. :)
    > > After using HTMLEncode, your string no longer contains "<!-- Main
    > > Content Begins -->". It contains "&lt;!-- Main Content Begins --&gt;", a
    > > fact which you can ascertain by writing the string to response, running
    > > the page and viewing source. You either have to do this:

    >
    > > strHTML = objXmlHttp.responseText
    > > Dim FullHTML : FullHTML = strHTML
    > > HTMLArr = split(FullHTML,"<!-- Main Content Begins -->")
    > > response.write Server.HTMLEncode(HTMLArr(1))

    >
    > > or this:

    >
    > > strHTML = objXmlHttp.responseText
    > > Dim FullHTML : FullHTML = Server.HTMLEncode(strHTML)
    > > HTMLArr = split(FullHTML,"&lt;!-- Main Content Begins --&gt;")
    > > response.write HTMLArr(1)

    >
    > > --
    > > Microsoft MVP -- ASP/ASP.NET
    > > Please reply to the newsgroup. The email account listed in my From
    > > header is my spam trap, so I don't check it very often. You will get a
    > > quicker response by posting to the newsgroup.

    >
    > oh, I did not know that <!-- will become &lt;!-- during this
    > encoding... Now I see. Allow me to fix this and I will come back here
    > with confirmation. Sorry, but within 6 hours from now. Thank you for
    > leading me by your hand!


    just an update: IT WORKS WELL WITH
    HTMLArr = split(FullHTML,"&lt;!-- Main Content Begins --&gt;")
    Thank you
     
    , Feb 8, 2007
    #11
    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. Replies:
    2
    Views:
    470
  2. Carlos Ribeiro
    Replies:
    11
    Views:
    702
    Alex Martelli
    Sep 17, 2004
  3. trans.  (T. Onoma)

    split on '' (and another for split -1)

    trans. (T. Onoma), Dec 27, 2004, in forum: Ruby
    Replies:
    10
    Views:
    218
    Florian Gross
    Dec 28, 2004
  4. Sam Kong
    Replies:
    5
    Views:
    246
    Rick DeNatale
    Aug 12, 2006
  5. Stanley Xu
    Replies:
    2
    Views:
    620
    Stanley Xu
    Mar 23, 2011
Loading...

Share This Page