Eliminating Duplicate Array entries

Results 1 to 2 of 2

Thread: Eliminating Duplicate Array entries

  1. #1
    Join Date
    Dec 1969

    Default Eliminating Duplicate Array entries

    How do I do this...<BR><BR>I&#039;ve stored a list of products in a 2 dimensional array:<BR>10 Different Products, 7 Fields<BR><BR>myProduct(10,7)<BR><BR>Now Field2 Has the category data:<BR><BR>myProduct(1,1) = CategoryNameA<BR>myProduct(2,1) = CategoryNameA<BR>myProduct(3,1) = CategorySectionB<BR><BR>What I want to do is display a list of Category Names without showing duplicates. The final output I&#039;m trying to get is:<BR><BR>CategoryNameA &#124 CategorySectionB &#124 CategoryListC &#124 CategoryDeptD<BR><BR>I&#039;ve tried using instr() to compare the data, but as you can see "Category" is in each name, therefore it only returns 1 result.<BR><BR>What is the most efficient way of doing this? I&#039;m new to ASP and having a really tough time with this portion of my code. If someone could give me a skeleton to work from...

  2. #2
    Join Date
    Dec 1969

    Default Really just two ways...

    (1) Sort the array first. Then it&#039;s easy to display only the non-duplicates by looking to see if the prior entry in the array is the same.<BR><BR>But sorting a 2D array is a pain in the neck and not very fast, so...<BR><BR>(2) Simply do an inner loop, looking to see if the same name has previously appeared. (Effectively, you are sorting "on the fly", but since you don&#039;t actually swap the rows this will be faster.)<BR><BR>So:<BR><BR>&#060;%<BR>For row = 1 To UBound(myProduct,1) <BR> dupe = False<BR> For check = 1 To row-1<BR> If myProduct(row,1) = myProduct(check,1) Then<BR> dupe = True<BR> Exit For<BR> End If<BR> Next<BR> If Not dupe Then<BR> Response.Write myProduce(row,1) ... etc. ... other info ...<BR><BR> End If<BR>Next<BR>%&#062;<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts