+ Reply to Thread
Results 1 to 6 of 6

Comparing two arrays what the best most efficient way

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Comparing two arrays what the best most efficient way

    Hi,

    I have two arrays. Both arrays contain file names. Both arrays are sorted in alphabetical order.

    WHat i want to do is the following:
    I want to compare one array to the other. If an entry in array1 is in array2 then i want to do "something". if an entry is in array1 but not in array2 then i dont care. If an entry is in array2 but not in array1 again i dont care.

    any ideas on an efficient way to do this?

  2. #2
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Comparing two arrays what the best most efficient way

    Hi welchs101, the following is an example of comparing two String Arrays.
    Please Login or Register  to view this content.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Comparing two arrays what the best most efficient way

    thanks for responding.

  4. #4
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Comparing two arrays what the best most efficient way

    No problem! And?

  5. #5
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Comparing two arrays what the best most efficient way

    Mordred, I think the implication is that the Arrays need not be of the same dimension and/or items in the same order ... ie "work" may be item 2 in strArray2.

    welchs101, you can either iterate the 2nd Array for each iteration of the 1st exiting upon match, e.g:

    Please Login or Register  to view this content.
    alternatively apply a Match function (binary given sort) to array2 (use Index if multi dimensional - assume given subject matter that case is irrelevant):

    Please Login or Register  to view this content.
    Given the speed of Arrays I suspect iteration would be quicker than the Match approach.

    The fact that the arrays are sorted is helpful and with thought may permit some restrictions within the iteration, however, given the potential for missing items in either array it might not be as simple as appears at first glance.
    Last edited by DonkeyOte; 08-06-2011 at 03:35 AM. Reason: typos

  6. #6
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Re: Comparing two arrays what the best most efficient way

    thanks guys...........very helpful indeed.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1