HighlanderSword Posted November 13, 2019 Posted November 13, 2019 Hello, Is there a way to search any array for multiple items in one call , and have it return the position number of the items in array separated by a semicolon. For an example an 2d array search column 0 for values 5,6,7,test,edit,merge , and when it finds a match for any of the search items return a string with the position in the array followed by a semicolon so that result can be used to delete the Items from the array, The array would be under 100 records with 15 columns?
Nine Posted November 13, 2019 Posted November 13, 2019 Just create your own ArrayFindAll, it is not very complicated after all. You need to search a 2d array based on column number with an array of searched values. “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
iamtheky Posted November 13, 2019 Posted November 13, 2019 (edited) Look at _ArraySearch with a compare value of 3? The comma delimited list needs to become a pipe delimited list to be passed as a regex saying 'this or this or this or this', but it should do the job. edit: I suppose the loop of those is pretty much arrayfindall, so yeah build yer own one of those Edited November 13, 2019 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
Nine Posted November 13, 2019 Posted November 13, 2019 Use this : #include <Array.au3> Local $aSearch = [5,6,7,"test","edit","merge"] Local $aArray[5][5] = [[0, 1, 2, 1, 1222], _ [4, 5, 5, 4, 5], _ [4, 1, 3, 1, "test"], _ [0, 3, 2, 1, "abcdef"], _ [1, 5, 5, 4, "merge"]] _ArrayDisplay($aArray, "2D array") Local $sSearch = "^" & _ArrayToString ($aSearch) & "$" ;MsgBox ($MB_SYSTEMMODAL,"",$sSearch) Local $aResult = _ArrayFindAll($aArray, $sSearch, Default, Default, Default, 3, 4) _ArrayDisplay($aResult, "Found in Column 4") “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) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
Malkey Posted November 14, 2019 Posted November 14, 2019 And another example. expandcollapse popup#include <Array.au3> ; https://www.autoitscript.com/forum/topic/200817-search-array-for-multiple-values-in-one-call/ Global $sSearch Local $aFind = [5, "[2-7]", 7, "test", "edit", "merge"] Local $aArray[6][5] = [[0, 1, 2, 1, 1223], _ [4, 5, 5, 4, 5], _ [4, 1, 3, 1, "testify"], _ [0, 3, 2, 1, "abcdef"], _ [4, 2, 3, 1, "This is a test."], _ [1, 5, 5, 4, "merge"]] _ArrayDisplay($aArray, "2D array") ; Find matching items. $aMatchIndices = _ArrayFindItems($aArray, $aFind, 1) ; <----------- This is the one call to search an array for multiple values. _ArrayDisplay($aMatchIndices, "Inndices (0-based) Matches", "", 0, Default, "Row|Column") ; Remove matching items For $i = 0 To UBound($aMatchIndices, 1) - 1 $aArray[$aMatchIndices[$i][0]][$aMatchIndices[$i][1]] = "-" ; Or StringRegExpReplace($aArray[$aMatchIndices[$i][0]][$aMatchIndices[$i][1]], "(" & $sSearch & ")", "") ; Next _ArrayDisplay($aArray, "Matched Items Deleted from original 2D array") ; $bSearchLiteral = 0 - Will match "test" in "testify", and, "[2-7]" will match all number characters 2 to 7 in each item of the array, $aArray. ; = 1 - Will not match "test" in "testify" (because of "\b"s in RE Pattern), and, all search characters in "$aSearch" array are matched literally ("\Q...\E"). ; Returns a 0-based array with row index of a matching item of $aArray in first column (Col 0), and, the ; column index of a matching item of $aArray in second column (col 1). ; Func _ArrayFindItems($aArray, $aSearch, $bSearchLiteral = 1) $sSearch = $bSearchLiteral ? "^\Q" & _ArrayToString($aSearch, "\E\b|\b\Q") & "\E$" : "^" & _ArrayToString($aSearch) & "$" ;MsgBox(0, "RegExp Pattern", $sSearch) ; $MB_OK = 0 Local $iRow = 0, $aRet[100][2] For $i = 0 To UBound($aArray, 1) - 1 For $j = 0 To UBound($aArray, 2) - 1 If StringRegExp($aArray[$i][$j], $sSearch) Then $aRet[$iRow][0] = $i ; Row index $aRet[$iRow][1] = $j ; Column index $iRow += 1 EndIf Next Next ReDim $aRet[$iRow][2] Return $aRet EndFunc ;==>_ArrayFindItems
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