Click here to Skip to main content
15,886,797 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

VB
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
strMessage = strMessage & strMatch.Value & " (character position " & _
strMatch.FirstIndex & ")" & vbCrLf
Next
End If
Wscript.Echo strMessage
Posted
Updated 24-Aug-14 20:24pm
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900