How to get the count of a word in a text file?
To find the count of the word in a file,use the following code.
Const ForReading = 1
Set fso = CreateObject( "Scripting.FileSystemObject" )
Set textFile = fso.OpenTextFile( "D:\a.txt", ForReading )
contents = textFile.ReadAll
textFile.Close
Set rgxp = New Regexp
rgxp.Pattern = "Searchstring"
rgxp.IgnoreCase = False
rgxp.Global = True
Set matches = rgxp.Execute( contents )
Print "Number of repetitions: " & matches.Count
Const ForReading = 1
Set fso = CreateObject( "Scripting.FileSystemObject" )
Set textFile = fso.OpenTextFile( "D:\a.txt", ForReading )
contents = textFile.ReadAll
textFile.Close
Set rgxp = New Regexp
rgxp.Pattern = "Searchstring"
rgxp.IgnoreCase = False
rgxp.Global = True
Set matches = rgxp.Execute( contents )
Print "Number of repetitions: " & matches.Count
Comments
Post a Comment