1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| Option Explicit
'Version 1
Function Occurrence(sFile, strFind,bCasse)
Const ForReading = 1
Dim fso, FL, txt, Ret, nbr,S
Set fso = CreateObject("Scripting.FileSystemObject")
Set FL = fso.OpenTextFile(sFile, ForReading, False)
nbr = 0
Do While Not FL.AtEndOfStream
' txt = "" ' mise en commentaire après après la remarque de ProgElecT que je remercie beaucoup
txt=FL.ReadLine
Ret = InStr(1, Lcase(txt), Lcase(strFind),0)
If Ret <> 0 Then
S = Mid(txt,Ret,Len(strFind))
'Condition pour la casse
If bCasse = True Then
If S = strFind Then nbr =nbr + 1
Else
If Ucase(S) = Ucase(strFind) Then nbr =nbr + 1
End If
End If
Loop
FL.Close
Occurrence = nbr
End Function |
Partager