Hari B

Hari B

  • NA
  • 139
  • 65.4k

Print Specific line in vb Script

Aug 23 2014 4:52 AM
i have one text file like below
 
This is Hareesh 
This is Sampath 
This is Hareesh
This is Sampath
This is Hareesh
This is Hareesh
This is Sampath 
This is Hareesh
This is Sampath 
This is Hareesh
This is Sampath 
This is Hareesh
 
i want print This is Hareesh only how many occurences that all will be print.
here is my code
 
Const ForReading = 1
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.Pattern = "Hareesh"
objRegEx.Ignorecase = true
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Users\Hareesh\Desktop\From_Sampath\Test.txt", ForReading)
strSearchString = objFile.ReadAll
objFile.Close
Set colMatches = objRegEx.Execute(strSearchString)
If colMatches.Count > 0 Then
strMessage = "The following user accounts were found:" & vbCrlf
For Each strMatch in colMatches
msgbox strMessage
strMessage = strMessage & strMatch.Value & " (character position " & _
strMatch.FirstIndex & ")" & vbCrLf
Next
End If
Wscript.Echo strMessage