G
Guillermo López-Anglada
Hi,
I have the following code to compare strings:
Private Function GetNumOfMatchingWords(ArrayToCompare() As String, _
ReferenceString As String)
Dim nWord As Long
Dim WordsFound As Long
For nWord = 0 To UBound(ArrayToCompare())
'palabra contenida en cadena...
If InStr(ReferenceString, ArrayToCompare(nWord)) > 0 Then
'aumentamos cómputo de palabras contenidas...
WordsFound = WordsFound + 1
End If
'siguiente palabra...
Next
GetNumOfMatchingWords = WordsFound
End Function
I basically convert a string into an "array of words" and then check whether each of these words is
contained within another string. Then I perform the same operation the other way around in order to find
the highest percentage of matching words between the two strings. This approach works for my purpose, but
as I have thousands of strings to compare, it isn't very efficient. Could someone suggest a faster method?
The whole process involves reading a text file (in binary mode), splitting the read buffer into lines,
then the strings into words and then calling this routine. I think this one is the bottleneck. I've tried
the Like operator as well, but it isn't flexible enough.
Regards,
Guillermo
I have the following code to compare strings:
Private Function GetNumOfMatchingWords(ArrayToCompare() As String, _
ReferenceString As String)
Dim nWord As Long
Dim WordsFound As Long
For nWord = 0 To UBound(ArrayToCompare())
'palabra contenida en cadena...
If InStr(ReferenceString, ArrayToCompare(nWord)) > 0 Then
'aumentamos cómputo de palabras contenidas...
WordsFound = WordsFound + 1
End If
'siguiente palabra...
Next
GetNumOfMatchingWords = WordsFound
End Function
I basically convert a string into an "array of words" and then check whether each of these words is
contained within another string. Then I perform the same operation the other way around in order to find
the highest percentage of matching words between the two strings. This approach works for my purpose, but
as I have thousands of strings to compare, it isn't very efficient. Could someone suggest a faster method?
The whole process involves reading a text file (in binary mode), splitting the read buffer into lines,
then the strings into words and then calling this routine. I think this one is the bottleneck. I've tried
the Like operator as well, but it isn't flexible enough.
Regards,
Guillermo