Counting the number of times a word appears in a file in QTP

sFileName="E:\test.txt"
sString="hello world"
Const FOR_READING = 1
Dim oFso, oTxtFile, sReadTxt, oRegEx, oMatches
Set oFso = CreateObject("Scripting.FileSystemObject")
Set oTxtFile = oFso.OpenTextFile(sFileName, FOR_READING)
sReadTxt = oTxtFile.ReadAll
Set oRegEx = New RegExp
oRegEx.Pattern = sString
oRegEx.IgnoreCase = bIgnoreCase
oRegEx.Global = True
Set oMatches = oRegEx.Execute(sReadTxt)
MatchesFound = oMatches.Count
Set oTxtFile = Nothing : Set oFso = Nothing : Set oRegEx = Nothing
msgbox MatchesFound
Counting the number of times a word appears in a file in QTP Counting the number of times a word appears in a file in QTP Reviewed by Animesh Chatterjee on January 24, 2010 Rating: 5

No comments:

Powered by Blogger.