Jump to content
Sign in to follow this  
lsakizada

Common array

Recommended Posts

lsakizada

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)!

Share this post


Link to post
Share on other sites
Melba23

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Spiff59

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.

Share this post


Link to post
Share on other sites
lsakizada

I love this forum! 5 minutes and 4 replies !!!!

Thank you all guys, the link from JohnOne contain the code and the comments from Melba23 is a short brief of it.

Regards. :idea:


Be Green Now or Never (BGNN)!

Share this post


Link to post
Share on other sites
Spiff59

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.