Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dictionary and regular expression

Status
Not open for further replies.

ajtsystems

IS-IT--Management
Jan 15, 2009
80
0
0
GB
Can anyone help me with the script below to search only for he regular expression and still only return the 1st 2 entries on the dictionary?

Dim oFSO, oTSIn, oDict, iCtr, iKey
searchstring = "Somestring"
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "^25-09-2007 Somestring"
Set oFSO = CreateObject("Scripting.FileSystemObject")


Dim arrFileLines()
i = 0
Set oTSIn = oFSO.OpenTextFile("c:\scripts\test.txt",1)
Set oDict = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", 1)
Set objFile1 = objFSO.OpenTextFile("C:\Scripts\results.txt", 2)

'check through text file and create 1d array
Do
oDict.Add iCtr, oTSIn.ReadLine
iCtr = iCtr + 1
Loop Until oTSIn.AtEndOfStream

' Echo header lines first
WScript.Echo oDict.Item(0)
WScript.Echo oDict.Item(1)

'if echo = instr then ok
I thinnkmaybe the code goes here...

objFile1.Close
 
[tt]'check through text file and create 1d array
[red]iCtr=0[/red]
Do [red]while not oTSIn.AtEndOfStream[/red]
[blue]s=oTSIn.ReadLine
if objRegEx.test(s) then
oDict.Add iCtr, oTSIn.ReadLine
iCtr = iCtr + 1
if iCtr>1 then exit do
end if[/blue]
Loop

' Echo header lines first
[red]for each key in oDict.keys
WScript.Echo oDict.Item(key)
next[/red]
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top