Redshift Posted January 10, 2023 Share Posted January 10, 2023 (edited) Hello, I'd really appreciate some help with my situation, if anyone can spare the time, since it's been driving me a bit crazy (I'm new to AutoIt). What I have: an array filled with IDs, let's call it $arrID: another array filled with different data, let's call it $arrData; column [2] in particular is of interest because it's filled with some of the IDs also present in $arrID (this makes sense because this array is the result of more manipulation which happens earlier and works as it should): Essentially, in one array I have just the IDs, in the other I have the complete data, matched as it should with those IDs. What I want: A new array, $Final which has, for every ID, the corresponding "StringsIWant" ; something like this: # 06 | 141 | String1MatchingWithID141 | # 07 | 141 | String2MatchingWithID141 | # 08 | 141 | String3MatchingWithID141 | # 09 | 142 | String1MatchingWithID142 | # 10 | 142 | String2MatchingWithID142 | # 11 | 143 | String1MatchingWithID143 | (...) Or ideally without the IDs being duplicated: # 06 | 141 | String1MatchingWithID141 | # 07 | | String2MatchingWithID141 | # 08 | | String3MatchingWithID141 | # 09 | 142 | String1MatchingWithID142 | # 10 | | String2MatchingWithID142 | # 11 | 143 | String1MatchingWithID143 | (...) I've been testing several loops using _ArraySearch to find matches between $arrID and $arrData, and then _ArrayAdd to fill a new array with all the data, but I'm steadily getting more and more confused with each attempt. I'd really appreciate some help with this, even just a few lines of basic code that I can try out; I'm holding out temporarily on sharing my code since I'd have to change most of it due to privacy issues, but if my details aren't clear I'll see what I can do. Thanks! Edited January 12, 2023 by Redshift Link to comment Share on other sites More sharing options...
Nine Posted January 10, 2023 Share Posted January 10, 2023 I would help if you could provide some basic code, especially the arrays definition. I don't care if it is hard-coded, I just don't want to create those arrays manually from scratch. SOLVE-SMART and Dan_555 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Redshift Posted January 12, 2023 Author Share Posted January 12, 2023 On 1/10/2023 at 4:56 PM, Nine said: I would help if you could provide some basic code, especially the arrays definition. I don't care if it is hard-coded, I just don't want to create those arrays manually from scratch. Those arrays are created from huge .xml files that I can't share; as such, I'm sharing two files containing the contents of the two arrays and some code to import everything in $arrID and $arrData, respectively. The arrays created as such are exactly like the ones I'm using to try and find what I need, except some names - for the sake of readability, and more fidelity to the original data, in the Data.xml file I used "String_(MyOriginalData)" instead of "StringIWant(MadeUpData)". I hope this is okay. #include <File.au3> #include <Array.au3> ; $arrID $IDPath = @ScriptDir & "\ID.xml" Dim $arrID _FileReadToArray ( $IDPath, $arrID ) _ArrayDisplay ( $arrID, "ID" ) ; $arrData $DataPath = @ScriptDir & "\Data.xml" Dim $arrData[0][4] _FileReadToArray ( $DataPath, $arrData, 4, "|" ) _ArrayDisplay ( $arrData, "Data" ) ID.xml Data.xml Link to comment Share on other sites More sharing options...
rudi Posted January 13, 2023 Share Posted January 13, 2023 (edited) In the data.xml (why XML? this is a plain TXT file, isn't it?) there are several duplicates in col 2 This might be helpful: The "Number column" is converted from STRING to NUMBER -- better to compare for your task, I believe.. Sorting numbers as STRING ends up in an inappropirate oder. For large data amounts you could nest two loops for the both arrays just comparing the "next portion" and stop, when you "passed" the match already, continuing with the next line in your data array. #include <File.au3> #include <Array.au3> ; $arrID $IDPath = @ScriptDir & "\ID.xml" ; comment to fix up forum code formatting Dim $arrID _FileReadToArray ( $IDPath, $arrID ,0) ; no count in element 0 for $i = 0 to UBound($arrID) - 1 $arrID[$i]=Number($arrID[$i]) ; convert string to numers for correct sorting Next _ArraySort($arrID) _ArrayDisplay ( $arrID, "ID" ) ; $arrData $DataPath = @ScriptDir & "\Data.xml" ; comment to fix up forum code formatting Dim $arrData[0][3] ; 3 columns, isnt it? _FileReadToArray ( $DataPath, $arrData, 0, "|" ) for $i = 0 to UBound ($arrData) - 1 $arrData[$i][2]=Number($arrData[$i][2]) ; convert string col 2 to numbers Next _ArraySort($arrData,0,0,0,2) _ArrayDisplay ( $arrData, "Data" ) Edited January 13, 2023 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE! 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