[英]how to calculate difference between two text value in excel?
兩個如何計算Excel中兩個值之間的差,是否有公式可以做到這一點
90123567.....90123569......difference=(1)
901123567....90123567......diffidence=(1)
謝謝。
也許您正在尋找的是Levenshtein距離- 兩個單詞之間的Levenshtein距離是將一個單詞轉換為另一個單詞所需的最小單字符編輯(即,插入,刪除或替換)次數
下面的UDF可以計算出來,但是我還沒有對其進行廣泛的測試。 我找到它的網址現在已失效。 它確實會為您提供的數字字符串給出答案。
Option Explicit
'********************************
'*** Compute Levenshtein Distance
'********************************
Public Function LD(ByVal s As String, ByVal t As String) As Long
Dim d() As Long ' matrix
Dim m As Long ' length of t
Dim n As Long ' length of s
Dim i As Long ' iterates through s
Dim j As Long ' iterates through t
Dim s_i As String ' ith character of s
Dim t_j As String ' jth character of t
Dim cost As Long ' cost
' Step 1
n = Len(s)
m = Len(t)
If n = 0 Then
LD = m
Exit Function
End If
If m = 0 Then
LD = n
Exit Function
End If
ReDim d(0 To n, 0 To m) As Long
' Step 2
For i = 0 To n
d(i, 0) = i
Next i
For j = 0 To m
d(0, j) = j
Next j
' Step 3
For i = 1 To n
s_i = Mid$(s, i, 1)
' Step 4
For j = 1 To m
t_j = Mid$(t, j, 1)
' Step 5
If s_i = t_j Then
cost = 0
Else
cost = 1
End If
' Step 6
d(i, j) = Minimum(d(i - 1, j) + 1, d(i, j - 1) + 1, d(i - 1, j - 1) + cost)
Next j
Next i
' Step 7
LD = d(n, m)
Erase d
End Function
'*******************************
'*** Get minimum of three values
'*******************************
Private Function Minimum(ByVal a As Long, _
ByVal b As Long, _
ByVal c As Long) As Long
Dim mi As Long
mi = a
If b < mi Then
mi = b
End If
If c < mi Then
mi = c
End If
Minimum = mi
End Function
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.