Jump to content

Common array


Recommended Posts

Hi,

I want to create third array from two unique arrays that not contain the common elements.

For example

Dim $aArray_A[3] = ["A","B","C"]

Dim $aArray_B[1] = ["A"]

The expected results:

Dim $aArray_C[2] = ["B","C"]

Please do not take an account case sensitive or not sensitive

Whats the best way to do it?

Edited by lsakizada

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

  • Moderators

billo,

Isn't that what _ArrayConcatenate does?

_ArrayConcatenate does what it says - it adds the 2 arrays together. :)

lsakizada,

Copy the larger array to the array you want to end with. Loop through the smaller array. For each element do an _ArraySearch in the copied array and _ArrayDelete any matches. At the end you have an array holding those elements from the larger array which are not in the smaller. :idea:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

There are a whole flock of useless _Array...() functions, but nothing that suits your need.

I'd think you'd need nested loops to manually compare your arrays and delete matches. Then you could go with an _ArrayConcatenate() and an _ArraySort() if needed. Maybe even throw in an _ArrayUnique() if you're concerned about dupes within a single source array.

Link to comment
Share on other sites

You might play with this...

#include <Array.au3>

Global $avArray1[5] = ["Valik", "Holger", "Jon", "Larry", "Jeremy"]
Global $avArray2[5] = ["Valik", "Cyberslug", "Nutster", "Tylo", "JdeB"]
Global $ylen = UBound($avArray2) - 1

For $x = 0 to UBound($avArray1) - 1
    For $y = 0 to $ylen
        If $avArray1[$x] = $avArray2[$y] Then
            ExitLoop
        EndIf
    Next
    If $y > $ylen Then _ArrayAdd($avArray2, $avArray1[$x])
Next

_ArrayDisplay($avArray2)

Whether you need to sort the result at the end, or perform an _ArrayUnique upon $avArray1 prior to combining them would be determined by your requirements.

Edit: poop. too slow!

Edited by Spiff59
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...