...

View Full Version : VB, Collecting data from a string



seetherage
07-30-2007, 05:09 PM
Hey guys, my deal is that I have a code sort of like this (html)


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

TheShaner
07-30-2007, 05:36 PM
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

ghostdog74
08-02-2007, 04:28 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum