Jump to content

array unique onlynumber


faustf
 Share

Recommended Posts

hi guys

i have  array like this

sku1
12.00
2.00
Taglia
32
32
Taglia coppa
A
Taglia torace
S
Fantasia
A righe
sku2
12.00
1.00
Taglia
34
34
Taglia coppa
A
AA
Taglia torace
S
Colore principale
Arancione
Colore esatto
Albicocca
sku3
12.00
1.00
Taglia
36
36
AA
S
Materiale
Lycra

i want  remove only number  replicated   how is possible do that  ??

i tryed  with  _arrayunique  , but  remove also  , duplicated word , exist an options???

thankz  at  all :)

 

Link to comment
Share on other sites

Arrayunique looks for anything doubled, tripled etc and deletes all but one instance.

Is that not what you are attempting to do?

turns out like this:

Spoiler
Row|Col 0
[0]|23
[1]|sku1
[2]|12.00
[3]|2.00
[4]|Taglia
[5]|32
[6]|Taglia coppa
[7]|A
[8]|Taglia torace
[9]|S
[10]|Fantasia
[11]|A righe
[12]|sku2
[13]|1.00
[14]|34
[15]|AA
[16]|Colore principale
[17]|Arancione
[18]|Colore esatto
[19]|Albicocca
[20]|sku3
[21]|36
[22]|Materiale
[23]|Lycra

 

 

Edited by l3ill
added example
Link to comment
Share on other sites

I would  remove only number replicates from an array this way.

#include <Array.au3>

; ------- Create Array ----------
$a = StringRegExp(StringRegExpReplace(FileRead(@ScriptName), "(?s)^.*#cs\v+|\v+#ce.*$", ""), "\s*(.+)\s*", 3)
_ArrayDisplay($a, "Original")
; ------- End of Create Array ----------

; Remove only number duplicates from array.
Local $sUniqueStr = "|"
For $i = UBound($a) - 1 To 0 Step -1
    If Not StringRegExp($a[$i], "[^\d.]") Then ; Check if the array element contains only digits, and maybe, a decimal point.
        If StringInStr($sUniqueStr, "|" & $a[$i] & "|") Then
            _ArrayDelete($a, $i) ; The number already exists in the $sUniqueStr string.
        Else
            $sUniqueStr &= $a[$i] & "|" ; Add only unique numbers to $sUniqueStr string.
        EndIf
    EndIf
Next
_ArrayDisplay($a, "Unique Numbers")

#cs
    sku1
    12.00
    2.00
    Taglia
    32
    32
    Taglia coppa
    A
    Taglia torace
    S
    Fantasia
    A righe
    sku2
    12.00
    1.00
    Taglia
    34
    34
    Taglia coppa
    A
    AA
    Taglia torace
    S
    Colore principale
    Arancione
    Colore esatto
    Albicocca
    sku3
    12.00
    1.00
    Taglia
    36
    36
    AA
    S
    Materiale
    Lycra
#ce

 

Link to comment
Share on other sites

This solution is suitable for small arrays or arrays not containing many duplicates, but using _ArrayDelete() is slow. If you have a large array, you should be able to speed up the process using a function to separate the numbers first, and then use _ArrayUnique() on them. The two processes can also be integrated into a single optimized function by rewriting _ArrayUnique() in a way that forces it to ignore non-numeric entries, but that's slightly more complex. This last method will be faster and would also preserve the order of remaining entries.

Edited by czardas
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...