Sign in to follow this  
Followers 0
leomoon

Checking Two Sets of Arrays

9 posts in this topic

Hello,

I have two sets of arrays. The first one is an output from user which can be any set of numbers. The second array has a list of 0-9 with A-J listed. I want to check every item in the first array and see which alphabet it represents. Sorry I couldn't come up with a better example than this. Any one knows how to check this?

#include 
Global $output[14]=['3','4','2','2','5','4','6','6','2','7','6','4','3','4']
Global $chart[10][2]=[ _
['1','A'], _
['2','B'], _
['3','C'], _
['4','D'], _
['5','E'], _
['6','F'], _
['7','G'], _
['8','H'], _
['9','I'], _
['0','J']]
;So the final output would be: "CDBBEDFFBGFDCD"

Share this post


Link to post
Share on other sites



Pseudo code:

Loop through array $output

Loop through array $chart

if element of $output = element of $chart Then

do whatever needs to be done

EndIf

Endloop

Endloop


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Awesome. Tnx. Here is the final script.

#include 
Global $output[14]=['3','4','2','2','5','4','6','6','2','7','6','4','3','4']
Global $chart[10][2]=[ _
['1','A'], _
['2','B'], _
['3','C'], _
['4','D'], _
['5','E'], _
['6','F'], _
['7','G'], _
['8','H'], _
['9','I'], _
['0','J']]
;So the final output would be: "CDBBEDFFBGFDCD"
$converted = ''
For $o=0 To UBound($output)-1
For $c=0 To UBound($chart,1)-1
If $output[$o]==$chart[$c][0] Then
$converted &= $chart[$c][1]
EndIf
Next
Next
ConsoleWrite($converted&@LF)

Share this post


Link to post
Share on other sites

To enhance performance you should leave the inner loop as soon as to entries match:

#include
Global $output[14] = ['3', '4', '2', '2', '5', '4', '6', '6', '2', '7', '6', '4', '3', '4']
Global $chart[10][2] = [ _
        ['1', 'A'], _
        ['2', 'B'], _
        ['3', 'C'], _
        ['4', 'D'], _
        ['5', 'E'], _
        ['6', 'F'], _
        ['7', 'G'], _
        ['8', 'H'], _
        ['9', 'I'], _
        ['0', 'J']]
;So the final output would be: "CDBBEDFFBGFDCD"
$converted = ''
For $o = 0 To UBound($output) - 1
    For $c = 0 To UBound($chart, 1) - 1
        If $output[$o] == $chart[$c][0] Then
            $converted &= $chart[$c][1]
            ExitLoop  ; <====
        EndIf
    Next
Next
ConsoleWrite($converted & @LF)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

isn't it easier to have it like:

[1] = 'A'

[2] = 'B'

then it could be done with 1 loop. Correct me if I am wrong. :shifty:


edited

Share this post


Link to post
Share on other sites

Correct. Then the code would look like this:

Global $output[14] = ['3', '4', '2', '2', '5', '4', '6', '6', '2', '7', '6', '4', '3', '4']
Global $chart[11] = ['', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
;So the final output would be: "CDBBEDFFBGFDCD"
$converted = ''
For $o = 0 To UBound($output) - 1
    $converted &= $chart[$output[$o]]
Next
ConsoleWrite($converted & @LF)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

replacing values in the original:

#include <Array.au3>
Global $output[14] = ['3', '4', '2', '2', '5', '4', '6', '6', '2', '7', '6', '4', '3', '4']
Global $chart[11] = ['', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J']
$converted = ''
For $i = 0 To UBound($output) - 1
    $output[$i] = $chart[$output[$i]]
Next
_ArrayDisplay ( $output)

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

I simplified the example here. In my own script I can't use only one loop cuz none of the arrays are numbers to use them as index number for the other one. I'm converting different Persian Unicode systems to each other.

But good optimization. :D

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
Sign in to follow this  
Followers 0