Subame:LevenshteinDistance
Description : this sub compare two strinss and return int as the result , more information can be found in :http://en.wikipedia.org/wiki/Levenshtein_distance
Dependencis: none
Description : this sub compare two strinss and return int as the result , more information can be found in :http://en.wikipedia.org/wiki/Levenshtein_distance
Dependencis: none
B4X:
Sub LevenshteinDistance(s As String, t As String) As Int
' d Is a table with m+1 rows AND n+1 columns
Dim m As Int=s.Length
Dim n As Int=t.Length
Dim d(m+2,n+2) As Int
For i=0 To m
d(i, 0) = i ' deletion
Next
For j=0 To n
d(0, j) = j ' insertion
Next
For j=1 To n
For i=1 To m
If s.CharAt(i-1) = t.CharAt(j-1) Then
d(i, j) = d(i-1, j-1)
Else
d(i, j) = minimum(d(i-1, j) + 1,d(i, j-1) + 1,d(i-1, j-1) + 1)
End If
Next
Next
Return d(m,n)
End Sub
Last edited: