' lehvenshsteinsche distance ' http://de.wikipedia.org/wiki/Levenshtein-Distanz Function match (str1, str2) Dim Matrix (), str1len, str2len, i, j, cost, m1, m2, m3 If (Not ((IsNull (str1) Or IsNull (str2)))) Then str1len = Len (str1) str2len = Len (str2) ReDim Matrix (str1len + 1, str2len + 1) ' populate the matrix For i=0 To str1len Matrix(i, 0) = i Next For j=0 To str2len Matrix(0, j) = j Next For i=1 To str1len For j=1 to str2len If (Mid (str1, i, 1) = Mid (str2, j, 1)) Then cost = 0 Else cost = 1 End If m1 = Matrix (i-1, j) + 1 m2 = Matrix (i, j-1) + 1 m3 = Matrix (i-1, j-1) + cost If ((m1 <= m2) And (m1 <= m3)) Then Matrix (i, j) = m1 End If If ((m2 <= m1) And (m2 <= m3)) Then Matrix (i, j) = m2 End If If ((m3 <= m2) And (m3 <= m1)) Then Matrix (i, j) = m3 End If Next Next match = Matrix(str1len - 1, str2len - 1) Else match = 667 End If End Function