2012-02-14 2 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 가지 배열이 나에게하는 array1의 차이를 제공해야 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

데이터베이스에 배열 데이터가 있습니까? 그렇다면 찾고있는 정보를 반환하는 쿼리를 쉽게 작성할 수 있습니다. –

+1

정렬에 대해 배우려면 [여기] (http://www.vbforums.com/showthread.php?t=473677)를 시작하는 것이 좋습니다. 정렬되지 않은 배열을 비교하려고 시도 할 곳이 없다고 생각합니다. –

+0

@GMastros nope 내가 왜 빠른 선택을 요구했는지 그 이유는 무엇입니까? 보안 저장소 문제에 대해서는 DB를 피했지만 아무런 선택도없는 것처럼 보입니다. –

답변

2

테이블에 대한 데이터베이스 부하를 생성하고 SQL을 사용 : 영원히 등의 복용이 비교도 ..

약간의 메모를 마칩니다. 수동으로 시도하는 데 너무 느리게 실행됩니다.

+0

나는 ur right ..를 추측했다 나는이 대답을 두려워했다. 그러나 db는 유일한 옵션 감사와 같다. –

관련 문제