Soledad

remove duplicated items from Array !!!

9 posts in this topic

hello everybody

I have array like this :

#include <Array.au3>

Local $aArray_Base[8] = ["1","2","3","1","2","2","5","6"]

_ArrayDisplay($aArray_Base, "Base array")

how can I remove duplicated items and set the new size of the Array ??

$aArray_Base[5] = ["1","2","3","5","6"]

thanks

Share this post


Link to post
Share on other sites



#4 ·  Posted (edited)

#include <Array.au3>

Local $aArray_Base[8] = ["1","2","3","1","2","2","5","6"]

_ArrayDisplay($aArray_Base, "Base array")
$aArray_Base=_ArrayUnique($aArray_Base,0,0,0,0)
_ArraySort($aArray_Base)
_ArrayDisplay($aArray_Base, "Final array")
Edit: removed item count in _arrayunique()

Edited by Exit
1 person likes this

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites

Since no one thought of it before I would say : _ArrayUnique  :)

1 person likes this

Share this post


Link to post
Share on other sites

thanks so much it works but there is a problem

the item "5" still duplicated !!

Share this post


Link to post
Share on other sites

#include <Array.au3>

Local $aArray_Base[8] = ["1","2","3","1","2","2","5","6"]

For $i = ubound($aArray_Base) - 1 to 1 step -1
    For $k = $i - 1 to 0 step - 1
        If $aArray_Base[$k] = $aArray_Base[$i] Then
            _ArrayDelete($aArray_Base , $k)
            $i -= 1
        EndIf
    Next
Next

_ArrayDisplay($aArray_Base)


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

@soledad:

Try the modified version in post #4. There was an error. Itemcount was not removed.

Edited by Exit
1 person likes this

My UDFs, Abbrevs and Snippets
If you like my post, just click the like button :) 

Share this post


Link to post
Share on other sites
#include <Array.au3>

Local $aArray_Base[8] = ["1","2","3","1","2","2","5","6"]

_ArrayDisplay($aArray_Base, "Base array")
$aArray_Base=_ArrayUnique($aArray_Base,0,0,0,0)
_ArraySort($aArray_Base)
_ArrayDisplay($aArray_Base, "Final array")
Edit: removed item count in _arrayunique()

 

thanks so much it works well

and thanks for all ^_^

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