Using InStr...

Results 1 to 3 of 3

Thread: Using InStr...

  1. #1
    Join Date
    Dec 1969

    Default Using InStr...

    I am trying to modify code from an article I got on ASPtoday. <BR>What the code does is pull from an XML document that has two child nodes KEYWORD and URL off of the parents node of PAGE. <BR>If I search for the whole KEYWORD string, as in,TOMATOES POTATOES ONIONS RADDISHES, I get back the URL, vegetables.html. But if I only search for TOMATOES, I get nothing back in the results...what I not using InStr correctly? Thanks<BR><BR>In the code, i have the following<BR><BR>Dim strSearch, objXML, rootNode, childNode, match<BR>strSearch = Request.Form("txtSearch")<BR>strSearch = UCase(strSearch)<BR>Dim pageNode, propertyNode<BR><BR>Set objXML = Server.CreateObject("Microsoft.XMLDOM")<BR>objXML. Load(Server.MapPath("database.xml"))<BR>Set rootNode = objXML.documentElement<BR><BR>If rootNode.hasChildNodes() Then<BR> For Each pageNode in rootNode.childNodes<BR> For Each propertyNode in pageNode.childNodes<BR> If propertyNode.nodeName = "KEYWORDS" Then<BR> If InStr(strSearch, propertyNode.Text) Then<BR> match = True<BR> End If<BR> End If<BR> If propertyNode.nodeName = "URL" Then<BR> If match = True Then<BR> Response.Write("&#060;A HREF=""" & propertyNode.Text & """&#062;" & propertyNode.Text & "&#060;/A&#062;<BR>")<BR> End If<BR> match = False<BR> End If<BR> Next<BR> Next<BR>End If<BR><BR>Set objXML = Nothing

  2. #2
    Join Date
    Dec 1969

    Default RE: Using InStr...

    Try<BR> If InStr(strSearch, propertyNode.Text) &#060;&#062; 0 Then <BR><BR>Not sure if VBS treats 0 as true or not. Also watch your case sensitivity... if cases aren&#039;t the same, read the docs on InStr() to see what parameter to pass to it to ignore case.<BR>

  3. #3
    Join Date
    Dec 1969

    Default Using InStr *BACKWARDS*???

    If InStr(strSearch, propertyNode.Text) Then<BR><BR>That says "if you find the contents of propertyNode.Text anywhere inside the contents of strSearch, then..."<BR><BR>Don&#039;t you want it to be "if you find the contents of strSearch anywhere inside the contents of PropertyNode.Text, then..." ???<BR><BR>To illustrate:<BR><BR>InStr( "ABC", "B" ) gives 2. "B" was found at position 2 in "ABC".<BR><BR>InStr( "B", "ABC" ) gives 0. You can&#039;t find "ABC" inside "B".<BR><BR>Did I guess right?<BR>

Posting Permissions

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