Jump to content
Sign in to follow this  

Array: Duplicate entries and sorting

Recommended Posts


Hi all, I'm new to the forum but I am using AutoIt since years.

I'm having some trouble with arrays, I need a fast solution for remove duplicate entries.


I have $FirstArray with 50.000 elements (many of these may be the same) to merge with $SecondArray which has 10.000 elements all different and alphabetically ordered but I want remove duplicate elements so I have a $FinalArray with both Arrays but no clones.

(I searched and found this topic but didn't help)

#include <Array.au3>
$FirstString = "john|tom|sam|mark|sam|betty|george|tony|tom|gus" ;Unsorted large array
$FirstArray = StringSplit($FirstString, "|")

$SecondString = "anna|betty|carl|donna|emily|fiona|gus|michael" ;Sorted array
$SecondArray = StringSplit($SecondString, "|")

Dim $FinalArray[50000] ;Not sure about this

; I thought something like this but the search has to be done for each array item and I can have more than 50.000 items
; Anyway this doesn't check for duplicate entries on $FirstArray ($SecondArray is already filtered and sorted)
For $i = 1 To UBound($FirstArray)-1
     If Not _ArrayBinarySearch($SecondArray, $FirstArray[$i]) Then
        _ArrayAdd($FinalArray, $FirstArray[$i])

_ArraySort($FinalArray) ;Sort Array (I need $FinalArray sorted)
_ArrayDisplay($FinalArray) ;Show

(by the way this doesn't even work)

Thanks in advance for your help

Hope you understand me

Edited by Lumbo

Share this post

Link to post
Share on other sites


Probably a faster way to do this (native Obj Script Dictionary), but it will still be competitive;

; ArrayDupesEx.au3; v3.2.11.1 of AutoIt
; _ArrayDupes(ByRef $arrItemsF, $iDelete = 0, $iDetails = 0)
#include<_ArraySortClib5v3.au3> ;@Saou
$FirstString = "john|tom|sam|mark|sam|betty|george|tony|tom|gus" ;Unsorted large array
$FirstArray = _StringSplit($FirstString, "|"); v3.2.11.1 of AutoIt

$SecondString = "anna|betty|carl|donna|emily|fiona|gus|michael" ;Sorted array
$SecondArray = _StringSplit($SecondString, "|")

global $arrdupes0=_ArrayDupes( $SecondArray,  1,  0); _ArrayDupes(ByRef $arrItemsF, $iDelete = 0, $iDetails = 0)
_ArrayDisplay($arrdupes0,"$arrdupes0;Dupes only;   "&UBound($arrdupes0)-1)
_ArrayDisplay($SecondArray,"$SecondArray Not Sorted, Dupes Removed;   "&UBound($SecondArray)-1)
;_ArraySortClib(ByRef $Array, $iMode = 1, $fDescend = False, $iStart = 0, $iEnd = 0, $iColumn = 0, $iWidth = 0)

_ArrayDisplay($SecondArray,"$SecondArray Sorted;   "&UBound($SecondArray)-1)
Best, Randall


Share this post

Link to post
Share on other sites

Great, ArrayDupes is what I searched for. I found it but could not understand how it works.

Your example made it clear.

Thank you both.


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.