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 27 28
| 'exercice 4
Public Function nboccurence(ByVal phrase As String, ByVal mot As String) As Integer
Dim res, longueur, lgmot As Integer
Dim caractere As String
res = 0
lgmot = Len(mot)
longueur = Len(phrase)
For i = 1 To longueur
caractere = Mid(phrase, i, 1)
Next i
For i = 1 To longueur
If Mid(caractere, i, lgmot) = mot Then res = res + 1
Next i
nboccurence = res
End Function
Sub principal2()
Dim chaine As String
Dim sschaine As String
Dim nb As Integer
chaine = InputBox("saisir une phrase")
sschaine = InputBox("saisir un mot")
nb = nboccurence(chaine, sschaine)
MsgBox (" la sous chaine apparait " & nb & " dans la chaine ")
End Sub |
Partager