Finding the non-matching values collection/array

Ask a Question related to ASP, Design and Development.

  1. #1

    Default Finding the non-matching values collection/array

    Hi all,

    Ok, lets say I have the following,

    Request.Form collection which produces this (as the element names)

    a
    b
    c
    d
    e
    f

    And I also have an array containg this

    a
    b
    c

    What I want to do is loop through both and response.write to the screen only
    the items that are not the same, so in this case I would see

    d
    e
    f

    displayed on the screen, I've tried a couple of things but its not working,
    has anyone got any suggestions...

    Cheers

    Robb


    Robb Meade Guest

  2. Similar Questions and Discussions

    1. Matching values of an 2 arrays then move
      i am pulling data via the param tags in to 2 different arrays. Here is what I want to happen: when value1 of the first array matches pullDate of...
    2. Array Sort Using Regex Matching Fails
      Over the years, I have periodically played with this syntax of regex matching within an array sort. I have tried a lot of syntax changes. Never...
    3. Finding the row index in a collection of rows
      So that I can find the pageindex in my datagrid, I need to know the index in a collection of rows where based on a record id. Right now, I have to...
    4. Problem finding datagrid in Page.controls collection
      You can find datagrid in page by refering the form. Gatagrid is a child control of Form. Here is the code ----------------- Dim ctl As New...
    5. Matching array index to values retrieved from database
      Hello friends, I have this dynamic array(shown below) that I need to match to values (1 - 10) that I am returning from the database via DSN...
  3. #2

    Default Re: Finding the non-matching values collection/array

    anyone got any ideas with this? I really could do with some help please :o)

    Robb


    Robb Meade Guest

  4. #3

    Default Sorted it now...

    for i = 0 to ubound(ARR2)
    found = "false"
    for j = 0 to ubound(ARR1)
    if (ARR2(i) = ARR1(j)) then
    found = "true"
    exit for
    end if
    next
    if found ="false" then
    strOutput=strOutput & ARR2(i) & ","
    ARR2temp = ARR2(i)
    end if
    next


    Robb Meade Guest

  5. #4

    Default Re: Sorted it now...

    Robb Meade wrote on 29 jun 2003 in
    microsoft.public.inetserver.asp.general:
    > for i = 0 to ubound(ARR2)
    > found = "false"
    > for j = 0 to ubound(ARR1)
    > if (ARR2(i) = ARR1(j)) then
    > found = "true"
    > exit for
    > end if
    > next
    > if found ="false" then
    > strOutput=strOutput & ARR2(i) & ","
    > ARR2temp = ARR2(i)
    > end if
    > next

    Where is ARR2temp used for ?
    You need to initialise strOutput
    Better use a boolean for "found"

    Let me try:

    strOutput=""
    for i = 0 to ubound(ARR2)
    found = false
    for j = 0 to ubound(ARR1)
    if ARR2(i) = ARR1(j) then
    found = true
    exit for
    end if
    next
    if not found then
    strOutput=strOutput & ARR2(i) & "<br>"
    end if
    next
    response.write strOutput

    =============================

    Even so, if ARR2 has duplicates not in ARR1, they will be written
    And if ARR1 has entries not in ARR2 they will not be written

    Perhaps it is better to
    1 delete all double entries inside each array
    2 put all values in one array arr3 and
    3 output all non-double entries ?

    This is step 3:

    for i=0 to ubound(arr3)
    for j=0 to ubound(arr3)
    found=false
    if arr3(i)=arr3(j) and i<>j then
    found=true
    exit for
    end if
    next
    if not found then
    response.write arr3(i) & "<br>"
    end if
    next


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan. Guest

  6. #5

    Default Re: Sorted it now...

    Evertjan. wrote on 29 jun 2003 in microsoft.public.inetserver.asp.general:
    > for i=0 to ubound(arr3)
    > for j=0 to ubound(arr3)
    > found=false
    > if arr3(i)=arr3(j) and i<>j then
    > .....
    damn, still not right, should be:

    for i=0 to ubound(arr3)
    found=false
    for j=0 to ubound(arr3)
    if arr3(i)=arr3(j) and i<>j then
    found=true
    exit for
    end if
    next
    if not found then
    response.write arr3(i) & "<br>"
    end if
    next


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
    Evertjan. Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139