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
| Option Explicit
'Version 2
Function Occurrence(sFile, strFind,bCasse)
Const ForReading = 1
Dim fso, FL, txt, Ret, nbr, S, tbl
Set fso = CreateObject("Scripting.FileSystemObject")
Set FL = fso.OpenTextFile(sFile, ForReading, False)
nbr = 0
Do
txt = FL.ReadLine
Ret = InStr(1 , Lcase(txt), Lcase(strFind),0)
tbl = Split(Lcase(txt),Lcase(strFind))
If Ret > 0 Then
S = Mid(txt,Ret,Len(strFind))
'Condition pour la CASSE
If bCasse = True Then
If S = strFind Then nbr = nbr + Ubound(tbl)
Else
If Ucase(S) = Ucase(strFind) Then nbr = nbr + Ubound(tbl)
End If
End If
Loop Until FL.AtEndOfStream
FL.Close
Occurrence = nbr
End Function |
Partager