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 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    USA
    Posts
    11
    Thanks
    1
    Thanked 1 Time in 1 Post

    VB, Collecting data from a string

    Hey guys, my deal is that I have a code sort of like this (html)

    PHP Code:
    <div id=contactlist>John1</div>
    <
    div id=contactlist>John2</div>
    <
    div id=contactlist>John3</div>
    <
    div id=contactlist>John4</div>
    <
    div id=contactlist>John5</div>
    <
    div id=contactlist>John6</div
    and I put that into a string in Visual Basic, What I want to do is search in that string all the Johns and add them to a listbox, but only the names, not that <div id=. . . or the </div> part.

    Please help!!

    Thank You!

  • #2
    Senior Coder TheShaner's Avatar
    Join Date
    Sep 2005
    Location
    Orlando, FL
    Posts
    1,126
    Thanks
    2
    Thanked 40 Times in 40 Posts
    Using the code from this support article - http://support.microsoft.com/kb/818802 - as an example and using the pattern ">john.*<" should get you a collection of all the "john" matches.

    Here's a resource for creating regular expressions in VB - http://www.aivosto.com/vbtips/regex.html

    -Shane

  • #3
    New Coder
    Join Date
    May 2006
    Posts
    39
    Thanks
    0
    Thanked 1 Time in 1 Post
    Code:
    Option Explicit
    Dim myFile,objFSO,objFile,line,found
    myFile="C:\myfile.txt"
    Set objFSO=CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(myFile,1)
    Do Until objFile.AtEndOfStream
    	line=objFile.ReadLine
    	If InStr(1,line,"john",vbTextCompare) > 0 Then
    		found=Replace(line,"<div id=contactlist>","")
    		found=Replace(line,"</div>","")
    		WScript.Echo "Found a john at" , line
    	End If 
    Loop


  •  

    Posting Permissions

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