Jump to content

Array Compare


Recommended Posts

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

Like: ArrayCompare ($ar1, $ar2)

HeidiRFind free applications, code examples and more on my site at:http://heidisdownloads.com/
Link to comment
Share on other sites

Search help for any of these

;_ArrayAdd

;_ArrayBinarySearch

;_ArrayConcatenate

;_ArrayDelete

;_ArrayDisplay

;_ArrayFindAll

;_ArrayInsert

;_ArrayMax

;_ArrayMaxIndex

;_ArrayMin

;_ArrayMinIndex

;_ArrayPop

;_ArrayPush

;_ArrayReverse

;_ArraySearch

;_ArraySort

;_ArraySwap

;_ArrayToClip

;_ArrayToString

;_ArrayTrim

8)

NEWHeader1.png

Link to comment
Share on other sites

  • Moderators

Search help for any of these

;_ArrayAdd

;_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.

Link to comment
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

HeidiRFind free applications, code examples and more on my site at:http://heidisdownloads.com/
Link to comment
Share on other sites

You can probably do a bit better than that :P

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

Your method would fail on

$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() ]

Link to comment
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.

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...