2012-02-14 35 views
1

我得到了2個可擴展的數組,其中包含字符串,我希望能夠比較兩個字符串以查看哪些字符串包含其他字符串。比較兩個字符串數組並返回各自在vb6中的差異性能良好

可以說,我的陣列,如:

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 

我的代碼確實做了比較,並給出了真正的答案,但由於缺乏性能造成的內部for each調用有沒有辦法做到這一點比較更快的方式?其採取像永遠完成這個比較..

也是一個小紙條:

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. 
+0

您是否擁有數據庫中的數組數據。如果是這樣,您可以輕鬆編寫一個查詢來返回您正在查找的信息。 – 2012-02-14 16:10:12

+1

如果你想了解排序,[這裏](http://www.vbforums.com/showthread.php?t=473677)將是一個很好的開始。我不認爲你會試圖比較未分類的數組。 – 2012-02-14 16:19:25

+0

@Gastros nope我沒有在數據庫中的數組這就是爲什麼我要求更快的方式,我避免數據庫的安全存儲問題,但似乎我沒有選擇。 – 2012-02-15 07:07:00

回答

2

與數據的量,創建一個數據庫,負載表和使用SQL。嘗試手動執行它會運行得太慢。

+0

我想你的權利..我害怕這個答案,但分貝似乎是唯一的選擇謝謝.. – 2012-02-15 07:02:47

相關問題