Renderer

Autoit Array Matching

21 posts in this topic

Hello there! Here we have 2 arrays :

global $array1[3] = ['A','B','C']
global $array2[3] = ['1','2','3']

how can i match the elements from those two Arrays? For example how can i match the first Array 'A' with the second Array '3'?

Thanks in advance!

Share this post


Link to post
Share on other sites



More info's please. Why should 'A' match 3?  What should matching C, and what B?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I'm not sure if this is what you mean. You need this: https://www.autoitscript.com/forum/topic/179779-_arraydeclarefromstring-_arraytodeclarationstring-_arrayshufflemultidim-_arraycompare-_arrayenumvalues-_arrayassign/

#include 'ArrayMultiDim.au3'

Global $array1[3] = ['A','B','C']
Global $array2[3] = ['1','2','3']

If _ArrayToDeclarationString($array1) == _ArrayToDeclarationString($array2) Then ; change == operator to = for case insensitive check
    MsgBox(0, "", "Arrays are identical.")
Else
    MsgBox(0, "", "Arrays are different.")
EndIf

Edit: Hmm it seems you mean something else.

Edited by czardas

Share this post


Link to post
Share on other sites

Hmm it seems what ? It actually means nothing  :mellow:

Share this post


Link to post
Share on other sites
3 hours ago, AutoBert said:

More info's please. Why should 'A' match 3?  What should matching C, and what B?

I wanted to make some array matching. I want to make the $array1 each element correspond with the $array2 each element.So the basic idea is to create a corresponded for $array1 in $array2 , like the images bellow.

image3.png

image2.png

image1.png

Share this post


Link to post
Share on other sites

Something like this:

$oDictionary = ObjCreate("Scripting.Dictionary")
$oDictionary.ADD("A", "1")
$oDictionary.ADD("B", "2")
$oDictionary.ADD("C", "3")

Or Like this:

$oDictionary = ObjCreate("Scripting.Dictionary")
$oDictionary.ADD("A", "3")
$oDictionary.ADD("B", "1")
$oDictionary.ADD("C", "2")

Regards
Alien.

Share this post


Link to post
Share on other sites

Not sure what the goal is here.  You could use a scripting dictionary like Alien has shown.  You could use another array to pair up the array indexes.  You could even use a 1 dim array with values and a 2 dim array to create pairs.  

Lots of options, but like I said...without knowing the goal it's hard to tailor/polish a solution.

Share this post


Link to post
Share on other sites

???

Global $array1[3] = ['A', 'B', 'C']
Global $array2[3] = ['1', '2', '3']

For $i1 = 0 To UBound($array1) - 1
    For $i2 = 0 To UBound($array2) - 1
        ConsoleWrite($array1[$i1] & " --> " & $array2[$i2] & @CRLF)
    Next
Next

 


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

@alien4u: in a Scripting Dictionary for each key can only exists one value.

@Chimp: seem that TE means your solution, the solution is showing all posible combinations of both arrays

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

2 hours ago, AutoBert said:

@alien4u: in a Scripting Dictionary for each key can only exists one value.

@Chimp: seem that TE means your solution, the solution is showing all posible combinations of both arrays

Hi @AutoBert
Of course in my example there is two different illustrative examples this is why I said "Like this" "OR like this", 2 different codes but not the same code twice in the same script.
Sorry If I was not clear enough. 

Regards
Alien.

Edited by alien4u
Typo

Share this post


Link to post
Share on other sites
5 hours ago, alien4u said:

Sorry If I was not clear enough. 

May be talking in native language is better, i am german

Share this post


Link to post
Share on other sites

Ich spreche nur wenig.  Ich spielte Fußball vor 15 Jahren.

And did 6-8 grade in Wurzburg, So as long as you are calling me something derogatory, or telling me to sit down on the bench, then I should understand just fine.


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

Share this post


Link to post
Share on other sites
1 hour ago, AutoBert said:

May be talking in native language is better, i am german

I don't understand what you mean but anyways I'm Cuban and the last time I check Spanish is more difficult than German.
But this is an English speaking forum so again I don't get what you mean.

Regards
Alien.

Share this post


Link to post
Share on other sites

spanish is much easier for me than german.  compound languages are a biatch inasmuch as they smash words together :)


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

Share this post


Link to post
Share on other sites

We should not probably discuss this here but is not the same in English? Contractions? and words like: meritless, childhood and so on, to many to list?

Anyways I don't get what he try to point.
 

And to be clear I mean no offend to anyone I just don't understand what @AutoBert try to point.

Regards
Alien.

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

eh, discussing things and going off topic are what nights are for.  And it was a joke to use inasmuch , which is three words smashed together, to say that is the issue with another language.

They do both have a ton of phoenitically similar sounding words, but thats probably indicative of all the Western Germanic languages.

Edited by iamtheky

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

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Hello. Just for fun.

 

#include <Crypt.au3>


Global $array1[3] = ['A', 'B', 'C']
Global $array2[3] = ['1', '2', '3']

Global $array3[5] = ['A', 'B', 'C', "Autoit", ":)"]
Global $array4[5] = ['3', '1', '2', "Rocks", ":S"]

_CreateMatch($array1, $array2) ;Create Match base in a fingerprint of array data
_CreateMatch($array3, $array4)

ConsoleWrite("Array Match: " & _CheckMatch($array1, $array2) & @CRLF) ;match
ConsoleWrite("Array Match: " & _CheckMatch($array3, $array4) & @CRLF) ;match

;change some array values to change the match
$array1[2] = ":("
$array3[3] = "Danyfirex"

ConsoleWrite("Array Match: " & _CheckMatch($array1, $array2) & @CRLF) ;not match
ConsoleWrite("Array Match: " & _CheckMatch($array3, $array4) & @CRLF) ;not match




Func _CheckMatch($aArray1, $aArray2)
    Local $sString = ""
    Local $sVar = ""
    If Not UBound($aArray1) = UBound($aArray2) Then Return SetError(1, 0, False)
    For $i = 0 To UBound($aArray1) - 1
        $sString &= $aArray1[$i] & $aArray2[$i]
    Next
;~  ConsoleWrite($sString & @CRLF)
    $sVar = "fingerprint" & Hex(_Crypt_HashData($sString, $CALG_MD5))
;~  ConsoleWrite($sVar & @CRLF)
    Return IsDeclared($sVar)
EndFunc   ;==>_CheckMatch

Func _CreateMatch($aArray1, $aArray2)
    Local $sString = ""
    Local $sVar = ""
    If Not UBound($aArray1) = UBound($aArray2) Then Return SetError(1, 0, False)
    For $i = 0 To UBound($aArray1) - 1
        $sString &= $aArray1[$i] & $aArray2[$i]
    Next
;~      ConsoleWrite($sString & @CRLF)
    $sVar = "fingerprint" & Hex(_Crypt_HashData($sString, $CALG_MD5))
;~      ConsoleWrite($sVar & @CRLF)
    If Not IsDeclared($sVar) Then
        Assign($sVar, 0, 2)
        Return SetError(0, 0, True)
    Else
        Return SetError(2, 0, False)
    EndIf
EndFunc   ;==>_CreateMatch

El español es bello lol

Saludos

Edited by Danyfirex

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

 

27 minutes ago, iamtheky said:

spanish is much easier for me than german.

59 minutes ago, iamtheky said:

Ich spreche nur wenig.  Ich spielte Fußball vor 15 Jahren.

Then your speaking perfect spanish, but understand the same german slang. Würzburg is < 50 km to my hometown.

@alien4u: it was just for clarify, but meanwhile i know: just 2 examples.

 

Edited by AutoBert

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

1 hour ago, AutoBert said:

 

@alien4u: it was just for clarify, but meanwhile i know: just 2 examples.

 

Here you lost me again. What you mean? 2 examples about what? Sorry I feel a little dump right now look like Cuban's beer is not as good as German ones(this is not a joke is a fact.)

Regards
Alien.

Edited by alien4u

Share this post


Link to post
Share on other sites

Living in south tx I am better with Spanish slang.  The difference between bavarian and franconian slang was like two different languages. 

Do you want all possibilities, or to be able to set the matches.  Can you make a complete one and have us divide it back into the original two arrays?


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

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