Jump to content
Sign in to follow this  

Strip duplicate and blank entries from an array

Recommended Posts


Using functions as _FileListToArray or StringSplit, you may get an array with several duplicate or blank entries. This function removes all duplicate and blank entries, and return a new array (without duplicate and blank entries). It also updates the element of index 0 (number of entries).

* It needs to #include <Array.au3>

; #FUNCTION# ======================================================================================================
; Name...........: ArrayStripDuplicate
; Description ...: Strips the duplicate items and blank space from given array
; Syntax.........: ArrayStripDuplicate($aArray)
; Parameters ....: $aArray - Input array
; Return values .: Success - The new array
;                  Failure - -1, sets @error to:
;                  |1 - $aArray is not an array
;                  |2 - $aArray is not a 1 dimensional array
; Author ........: Renan Maronni <renanmaronni@hotmail.com>
; Modified.......:
; Remarks .......: It needs the #include <Array.au3>
; Related .......:
; Link ..........:
; Example .......:
; =================================================================================================================

Func ArrayStripDuplicate($aArray)

    Local $aNewArray[1]
    Local $iArraySize = UBound($aArray)

    If (Not IsArray($aArray)) Then
        Return SetError(1, 0, -1)

    If (UBound($aArray, 0) <> 1) Then
        Return SetError(2, 0, -1)

    For $i = 1 To ($iArraySize - 1)
        If (_ArraySearch($aNewArray, $aArray[$i]) = -1) Then
            _ArrayAdd($aNewArray, $aArray[$i])

    $aNewArray[0] = UBound($aNewArray) - 1

    Return $aNewArray

EndFunc   ;==>ArrayStripDuplicate

Share this post

Link to post
Share on other sites

What about the build in function _ArrayUnique()? It is slow but working...



Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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.