amin84 Posted July 5, 2012 Share Posted July 5, 2012 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 comment Share on other sites More sharing options...
water Posted July 5, 2012 Share Posted July 5, 2012 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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
amin84 Posted July 5, 2012 Author Share Posted July 5, 2012 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 comment Share on other sites More sharing options...
water Posted July 5, 2012 Share Posted July 5, 2012 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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
amin84 Posted July 5, 2012 Author Share Posted July 5, 2012 Tnx for the tip. Link to comment Share on other sites More sharing options...
E1M1 Posted July 5, 2012 Share Posted July 5, 2012 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. edited Link to comment Share on other sites More sharing options...
water Posted July 5, 2012 Share Posted July 5, 2012 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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
jdelaney Posted July 5, 2012 Share Posted July 5, 2012 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 comment Share on other sites More sharing options...
amin84 Posted July 5, 2012 Author Share Posted July 5, 2012 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now