Jump to content

Creating and filling an array from _ArraySearch matches


Recommended Posts

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:

1.png.eec91c2321da0d1308cec674aaf3ad77.png

 

  • 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):

2.png.f63f09a6dc8fb92e2b9192263c8619d4.png

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 by Redshift
Link to post
Share on other sites

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.

Link to post
Share on other sites
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 post
Share on other sites

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 by rudi

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

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