Jump to content

Checking Two Sets of Arrays


Recommended Posts

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"
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 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

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)
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 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

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 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

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

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...