aeun01 Posted November 13, 2022 Share Posted November 13, 2022 hello! Given the following two-dimensional arrays A and B, I want to find out where B is located in A. It's a very difficult challenge for me, so I'm asking for help. I don't know which part to improve. Please advise if you have any suggestions for improvement or other methods. That is, I want the result to be 6 rows and 4 columns. Thank you! test.au3 Link to comment Share on other sites More sharing options...
AutoBert Posted November 13, 2022 Share Posted November 13, 2022 My try with StringInStr: #include <Array.au3> Global $A = [[1, 2, 22,'a4', 20, 22, 66, 23], _ [ 2, 5, 23,'a4', 34, 31, 34, 55], _ [ 2, 5, 23,'a4', 34, 31, 34, 55], _ [ 1, 2, 22,'a4', 20, 22, 66, 23], _ [ 2, 5, 23,'a4', 34, 31, 34, 55], _ [ 2, 5, 23,'a4', 34, 31, 34, 55], _; 6,4 [ 5, 1, 20,'a4', 22, 44, 55, 66], _; [ 6, 7, 10,'a4', 55, 66, 33, 44], _; [ 5, 1, 20,'a4', 55, 66, 33, 44], _ [ 2, 5, 23,'a4', 22, 44, 55, 66], _ [ 1, 2, 86,'a4', 55, 66, 33, 44]] Global $B = [['a4', 34, 31, 34, 55], _ [ 'a4', 22, 44, 55, 66], _ [ 'a4', 55, 66, 33, 44]] ;MsgBox($MB_SYSTEMMODAL,'',UBound($A,2)&' '&UBound($b,2) ) ;3임 3,7 Global $sA= _ArrayToString($A) $sA = StringSplit($sA, @CRLF, 3) ;_ArrayDisplay($sA) Global $sB= _ArrayToString($B) $sB = StringSplit($sB, @CRLF, 3) ;_ArrayDisplay($sB) For $i = 0 To UBound($sB) -1 For $j = 0 To UBound($sA) -1 $iPos = StringInStr($sA[$j], $sB[$i]) If $iPos Then ConsoleWrite('Match [' & $j & '|' & $i & ']: ' & $sB[$i] & ' is in ' & $sA[$j] & @CRLF) Next Next please test the output. Link to comment Share on other sites More sharing options...
Solution Nine Posted November 13, 2022 Solution Share Posted November 13, 2022 (edited) This should give right result : #include <Array.au3> Global $A = [[1, 2, 22,'a4', 20, 22, 66, 23], _ [ 2, 5, 23,'a4', 34, 31, 34, 55], _ [ 2, 5, 23,'a4', 34, 31, 34, 55], _ [ 1, 2, 22,'a4', 20, 22, 66, 23], _ [ 2, 5, 23,'a4', 34, 31, 34, 55], _ [ 2, 5, 23,'a4', 34, 31, 34, 55], _; 6,4 [ 5, 1, 20,'a4', 22, 44, 55, 66], _; [ 6, 7, 10,'a4', 55, 66, 33, 44], _; [ 5, 1, 20,'a4', 55, 66, 33, 44], _ [ 2, 5, 23,'a4', 22, 44, 55, 66], _ [ 1, 2, 86,'a4', 55, 66, 33, 44]] Global $B = [['a4', 34, 31, 34, 55], _ [ 'a4', 22, 44, 55, 66], _ [ 'a4', 55, 66, 33, 44]] Local $a1 = StringSplit(_ArrayToString($A), @CRLF, 3) Local $b1 = StringSplit(_ArrayToString($B), @CRLF, 3) Local $iPos, $iTmp For $i = 0 to UBound($a1) - UBound($b1) $iPos = StringInStr($a1[$i], $b1[0], $STR_CASESENSE) If Not $iPos Then ContinueLoop For $j = 1 To UBound($b1) - 1 $iTmp = StringInStr($a1[$i + $j], $b1[$j], $STR_CASESENSE) If $iTmp <> $iPos Then ContinueLoop 2 Next StringReplace(StringLeft($a1[$i], $iPos), "|", "|", 0, $STR_CASESENSE) Exit MsgBox($MB_SYSTEMMODAL, "Found", "At " & $i + 1 & "/" & @extended + 1) Next MsgBox($MB_SYSTEMMODAL, "Error", "Not found") There is 2 very important assumptions I made : There is only 1 possible match of $b1[x] within any line of $a1 Cells in $A have same length for each columns If those assumptions are not respected, you will need to adapt my code Edited November 13, 2022 by Nine “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...
aeun01 Posted November 14, 2022 Author Share Posted November 14, 2022 I tested the code you posted. Running the code posted by AutoBert didn't give me the desired result, but thanks for the reply! The code 9 wrote was what I wanted. It runs fine. Thank you! 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