- Offizieller Beitrag
Auch diesem Wunsch werden wir gerecht. Doppel löschen ohne Sortierung.
- Array 1D/2D wird automatisch erkannt
- Doppel werden gelöscht
Edit:
- Beschränkung für Größe 2.te Dimension aufgehoben
- Funktion gibt bei Erfolg die Anzahl der Löschungen zurück
- Funktionsname angepaßt in: _Array2DDblDel( )
Spoiler anzeigen
#include <array.au3>
Dim $ar[5], $ar2[5][2]
$ar[0] = "otto"
$ar[1] = "aha"
$ar[2] = "otto"
$ar[3] = "b"
$ar[4] = "aha"
$ar2[0][0] = "otto"
$ar2[1][0] = "aha"
$ar2[2][0] = "otto"
$ar2[3][0] = "b"
$ar2[4][0] = "ah"
$ar2[0][1] = "c"
$ar2[1][1] = "ha"
$ar2[2][1] = "c"
$ar2[3][1] = "bor"
$ar2[4][1] = "aha"
_ArrayDisplay($ar, "1D mit Doppel")
_Array2DDblDel($ar)
_ArrayDisplay($ar, "1D Doppel gelöscht")
_ArrayDisplay($ar2, "2D mit Doppel")
_Array2DDblDel($ar2)
_ArrayDisplay($ar2, "2D Doppel gelöscht")
;----------------------------------------------------------------------------------------------------------------------
; Function _Array2DDblDel(ByRef $ARRAY [, $CASESENS=0])
;
; Description - From an 1D/2D Array will delete double entries (2D -> combination by '[n][0]' to '[n][x]').
; - Autodetection 1D/2D Array
; - By using string, you can choose case sensitivity.
;
; Parameter $ARRAY: Array to sort
; optional $CASESENS: Case sensitivity off[0] or on[1] (default 0)
;
; Return Succes ByRef Array without doubles
; Count of doubles
; Failure 0 and set @error = 1; no array
;
; Author BugFix ([email='bugfix@autoit.de'][/email])
;----------------------------------------------------------------------------------------------------------------------
Func _Array2DDblDel(ByRef $ARRAY, $CASESENS=0)
Local $iDIM, $arTmp[1] = [''], $dbl = 0, $count = 0
If ( Not IsArray($ARRAY) ) Then
SetError(1)
Return 0
EndIf
$Ubound2nd = UBound($ARRAY,2)
If @error = 2 Then
For $i = 0 To UBound($ARRAY)-1
$dbl = 0
For $k = 0 To UBound($arTmp)-1
Switch $CASESENS
Case 0
If $arTmp[$k] = $ARRAY[$i] Then
$dbl = 1
$count += 1
EndIf
Case 1
If $arTmp[$k] == $ARRAY[$i] Then
$dbl = 1
$count += 1
EndIf
EndSwitch
Next
If $dbl = 0 Then
If $arTmp[0] = "" Then
$arTmp[0] = $ARRAY[$i]
Else
ReDim $arTmp[UBound($arTmp)+1]
$arTmp[UBound($arTmp)-1] = $ARRAY[$i]
EndIf
Else
$dbl = 0
EndIf
Next
Else
ReDim $arTmp[1][$Ubound2nd]
$arTmp[0][0] = ''
$x = 0
For $i = 0 To UBound($ARRAY)-1
$dbl = 0
$val = ''
$valTmp = ''
For $l = 0 To $Ubound2nd-1
$val &= $ARRAY[$i][$l]
Next
For $k = 0 To UBound($arTmp)-1
For $l = 0 To $Ubound2nd-1
$valTmp &= $arTmp[$k][$l]
Next
Switch $CASESENS
Case 0
If $valTmp = $val Then
$dbl = 1
$count += 1
EndIf
Case 1
If $valTmp == $val Then
$dbl = 1
$count += 1
EndIf
EndSwitch
Next
If $dbl = 0 Then
If $x = 1 Then ReDim $arTmp[UBound($arTmp)+1][$Ubound2nd]
For $l = 0 To $Ubound2nd-1
If $arTmp[0][0] = '' Or $x = 0 Then
$arTmp[0][$l] = $ARRAY[0][$l]
If $l = $Ubound2nd-1 Then $x = 1
Else
$arTmp[UBound($arTmp)-1][$l] = $ARRAY[$i][$l]
$x = 2
If $l = $Ubound2nd-1 Then $x = 1
EndIf
Next
Else
$dbl = 0
EndIf
Next
EndIf
$ARRAY = $arTmp
Return $count
EndFunc ; ==>_ArrayDblDel