代码:
Function isDup(tweet1 As String, tweet2 As String, threshold As Double) As Boolean
Dim sameWordCount As Integer
Dim i As Integer
Dim j As Integer
Dim numOfWords As Integer
sameWordCount = 0
words1 = Split(tweet1)
words2 = Split(tweet2)
If (UBound(words1) - LBound(words1) + 1) >= (UBound(words2) - LBound(words2) + 1) Then
numOfWords = UBound(words2) - LBound(words2) + 1
For i = LBound(words2) To UBound(words2)
Debug.Print "i: " & i & "/" & UBound(words2)
For j = LBound(words1) To UBound(words1)
Debug.Print "j: " & j & "/" & UBound(words1)
If StrComp(words1(i), words2(j), vbTextCompare) = 0 Then
sameWordCount = sameWordCount + 1
Exit For
End If
Next j
Next i
If threshold * (UBound(words1) - LBound(words1) + 1) > sameWordCount Then
isDup = False
Else
isDup = True
End If
Else
numOfWords = UBound(words1) - LBound(words1) + 1
For i = LBound(words1) To UBound(words1)
For j = LBound(words2) To UBound(words2)
If StrComp(words1(i), words2(j), vbTextCompare) = 0 Then
sameWordCount = sameWordCount + 1
Exit For
End If
Next j
Next i
If threshold * (UBound(words2) - LBound(words2) + 1) > sameWordCount Then
isDup = False
Else
isDup = True
End If
End If
Debug.Print sameWordCount & "/" & numOfWords & " words the same"