# Array Compare

## Recommended Posts

If there an easy way to compare two 1D arrays similar to StringCompare ( "string1", "string2")?

Like: ArrayCompare (\$ar1, \$ar2)

##### Share on other sites

Search help for any of these

;_ArrayBinarySearch

;_ArrayConcatenate

;_ArrayDelete

;_ArrayDisplay

;_ArrayFindAll

;_ArrayInsert

;_ArrayMax

;_ArrayMaxIndex

;_ArrayMin

;_ArrayMinIndex

;_ArrayPop

;_ArrayPush

;_ArrayReverse

;_ArraySearch

;_ArraySort

;_ArraySwap

;_ArrayToClip

;_ArrayToString

;_ArrayTrim

8)

##### Share on other sites

Search help for any of these

;_ArrayBinarySearch

;_ArrayConcatenate

;_ArrayDelete

;_ArrayDisplay

;_ArrayFindAll

;_ArrayInsert

;_ArrayMax

;_ArrayMaxIndex

;_ArrayMin

;_ArrayMinIndex

;_ArrayPop

;_ArrayPush

;_ArrayReverse

;_ArraySearch

;_ArraySort

;_ArraySwap

;_ArrayToClip

;_ArrayToString

;_ArrayTrim

8)

Or use the search feature on the forum?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

Thanks for the info. I didn't find what I was looking for so I wrote my own (below).

CODE
Func array_compare(\$ar1, \$ar2)

Local \$str1="", \$str2=""

For \$i = 0 to ubound(\$ar1) -1

\$str1 &= \$ar1[\$i]

Next

For \$i = 0 to ubound(\$ar2) -1

\$str2 &= \$ar2[\$i]

Next

Return StringCompare(\$str1, \$str2, 1)

Endfunc

##### Share on other sites

You can probably do a bit better than that

```Func _ArrayStringCompare(\$avArray1, \$avArray2, \$iFlag = 0)
Local \$iUpper = UBound(\$avArray1)
If UBound(\$avArray2) < \$iUpper Then \$iUpper = UBound(\$avArray2)

Local \$iCmp
For \$i = 0 To \$iUpper - 1
\$iCmp = StringCompare(\$avArray1[\$i], \$avArray2[\$i], \$iFlag)
If \$iCmp Then Return \$iCmp
Next

Return 0
EndFunc```

\$avArray1 = ["a", "b"]

\$avArray2 = ["ab"]

It would report the two arrays to be equal (they're not).

Edited by -Ultima-

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

##### Share on other sites

I wrote a set of functions for dumping information from variables a while ago. You can find it here. If you include that file, you can do something like this:

```#include <Variable.au3>

\$array = StringSplit('Hello', '')
\$array2 = StringSplit('Hello!', '')

If _VarDump(\$array) == _VarDump(\$array2) Then
; Match
EndIf```

I don't know how efficient that would be though.

*Off topic note: _VarDump doesn't work on structs in the current version of AutoIt.

##### Share on other sites

Thanks for the code suggestions guys! They were very helpful! :-)

## Create an account

Register a new account