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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
Function distance(s1 As String, s2 As String) As Integer
Dim l1 As Integer
Dim l2 As Integer
Dim d() As Integer
Dim i As Integer
Dim j As Integer
Dim cout As Integer
Dim effacement As Integer
Dim insertion As Integer
Dim substitution As Integer
Dim mini As Integer
Dim temp As String
l1 = Len(s1)
l2 = Len(s2)
ReDim d(0 To l1, 0 To l2)
For i = 0 To l1
d(i, 0) = i
Next i
For j = 0 To l2
d(0, j) = j
Next j
For i = 1 To l1
For j = 1 To l2
If UCase(Mid(s1, i, 1)) = UCase(Mid(s2, j, 1)) Then
cout = 0
Else
cout = 1
End If
effacement = d(i - 1, j) + 1
insertion = d(i, j - 1) + 1
substitution = d(i - 1, j - 1) + cout
mini = effacement
If insertion < mini Then mini = insertion
If substitution < mini Then mini = substitution
d(i, j) = mini
Next j
Next i
distance = d(l1, l2)
'For i = 0 To l1
'temp = ""
'For j = 0 To l2
'temp = temp & d(i, j) & ";"
'Next j
'temp = Left(temp, Len(temp) - 1)
'Debug.Print temp
'Next i
End Function |
Partager