Arrays 在vb6中比较两个字符串数组并返回每个数组的差异,性能良好
我得到了两个可扩展的数组,其中包含字符串,我想将这两个数组相互比较,看看哪些数组包含其他数组不包含的字符串 假设我的数组如下所示:Arrays 在vb6中比较两个字符串数组并返回每个数组的差异,性能良好,arrays,performance,vb6,comparison,Arrays,Performance,Vb6,Comparison,我得到了两个可扩展的数组,其中包含字符串,我想将这两个数组相互比较,看看哪些数组包含其他数组不包含的字符串 假设我的数组如下所示: ARRAY - 1 ARRAY - 2 a1 a1 a2 a2 a3 a3 a9 a4 a10 a8 a11 a10 a12
ARRAY - 1 ARRAY - 2
a1 a1
a2 a2
a3 a3
a9 a4
a10 a8
a11 a10
a12 a11
我想得到如下结果:
ARRAY - 4 ARRAY - 5 ARRAY - 6
a9 a4 a1
a12 a8 a2
a3
a10
a11
另外3个不同的数组应该会给出数组1与数组2的差异
-array4 here gives the strings that is included in array1 but not found in array2
-array5 here gives the strings that is included in array2 but not found in array1
-array6 here gives the strings that is found in both
为此,我编写了代码:
i = 0
j = 0
For Each innerElement1 In CompareElement1 'CompareElement1 is the array1 here
NoneFound = 1
'Ones thats in first element also found in second element..
For Each innerElement2 In CompareElement2 'CompareElement2 is the array2 here
If innerElement1 = innerElement2 Then
'Expand array
ReDim Preserve IncludedInBoth(0 To UBound(IncludedInBoth) + 1)
IncludedInBoth(i) = innerElement1
'Item found in both so NoneFound is 0.
NoneFound = 0
i = i + 1
End If
Next
'Ones thats in first element but not found in second element..
If NoneFound = 1 Then
'Expand array
ReDim Preserve NotIncludedInElem2(0 To UBound(NotIncludedInElem2) + 1)
NotIncludedInElem2(j) = innerElement1
j = j + 1
End If
Next
'Seperate Comparison for the ones that found in second element _
but not found in first element..
i = 0
For Each innerElement1 In CompareElement2
NoneFound = 1
'Ones thats in second element also found in first element.
For Each innerElement2 In IncludedInBoth
If innerElement1 = innerElement2 Then
'Item found in both so NoneFound is 0.
NoneFound = 0
End If
Next
'Ones thats in second element but not found in first element..
If NoneFound = 1 Then
'Expand array
ReDim Preserve NotIncludedInElem1(0 To UBound(NotIncludedInElem1) + 1)
NotIncludedInElem1(i) = innerElement1
i = i + 1
End If
Next
我上面的代码准确地进行了比较并给出了正确的答案,但是由于每个调用的内部都会导致性能不足,有没有一种方法可以与更快的方法进行比较?完成这项工作要花很长时间
还有一点需要注意:
array1 and array2 are two different sized arrays that contains thousands(~100.000)of strings in each.
also they are not in order. i would like to learn how to order them alphabetically.
使用这些数据量,创建一个数据库,加载到表中,然后使用SQL。如果尝试手动执行,它将运行得太慢。数据库中是否有阵列数据。如果是这样的话,你可以很容易地编写一个查询来返回你正在寻找的信息。如果你想了解排序,这将是一个很好的开始。我认为你在比较未排序的数组时不会有任何进展。@GMastros不,我没有数据库中的数组这就是为什么我要求更快的方法来避免数据库的安全存储问题,但似乎我没有选择。我想你是对的。。我害怕这个答案,但db似乎是唯一的选择谢谢。。