CFLam Posted May 22, 2020 Posted May 22, 2020 (edited) Hello all, I create an array with combination of 4 numbers from 99 i.e. 99C4 e.g. the array $myArray contain: 1--2--3--4, 1--2--3--5... 96--97--98--99 (yes, I join 4 numbers by '--' to become a 'string and put into an array) Then I have a data file with various combinations e.g. 13--17--33--88. 1--2--3--45 Then I use _arraysearch(($myArray,$inValue,0,0,0,0,1,0) to see how many occurrence of the data in the array and the expected result is something like that: Value Count 1--2--3--4 2 1--2--3--5 0 1--2--3--6 4 But I find that 1--2--3--44 also count into 1--2--3--4 !!!!! Seems that substring of inValue will used to perform partial match by _arraysearch function!!! How can I make arraysearch perform exact match for me ? Thanks. Regds LAM Chi-fung Edited May 22, 2020 by CFLam enrich information
Bert Posted May 22, 2020 Posted May 22, 2020 look at using regex The Vollatran project My blog: http://www.vollysinterestingshit.com/
CFLam Posted May 22, 2020 Author Posted May 22, 2020 2 hours ago, Bert said: look at using regex Set iCompare to 3 ? I am not familar with RegEx....
Musashi Posted May 22, 2020 Posted May 22, 2020 4 hours ago, CFLam said: How can I make arraysearch perform exact match for me ? Thanks You could also work without _ArraySearch. #include <Array.au3> Global $sSearch, $iCount = 0 Global $aTestArr[6]= ["1--2--3--4", _ "3--3--1--6", _ "1--2--3--44", _ "77--12--3--6", _ "1--2--3--4", _ "3--9--3--4"] _ArrayDisplay($aTestArr) $sSearch = "1--2--3--4" For $i = 0 To UBound($aTestArr) - 1 If $aTestArr[$i] == $sSearch Then ConsoleWrite("+ Index = " & $i & " Searchstring found !" & @CRLF) $iCount += 1 EndIf Next ConsoleWrite("< >>>> " & $sSearch & " was found " & $iCount & " time(s)" & @CRLF & @CRLF) FrancescoDiMuro and TheXman 2 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
Musashi Posted May 23, 2020 Posted May 23, 2020 Alternative approach : If you still prefer a solution with AutoIt's standard _Array* functions, then _ArrayFindAll is probably better suited than _ArraySearch . This returns an array with all matching indexes. The size of the array (UBound) is your counter. #include <Array.au3> Global $sSearch, $aResultArr, $iCount = 0 Global $aSearchArr[8]= ["1--2--3--4", _ "3--3--1--6", _ "1--2--3--44", _ "77--2--3--6", _ "1--2--3--4", _ "7--11--11--16", _ "1--2--3--4", _ "3--9--3--4"] _ArrayDisplay($aSearchArr, "SearchArray") ; *** just to display the array $sSearch = "1--2--3--4" $aResultArr = _ArrayFindAll($aSearchArr, $sSearch, Default, Default, 0, 2, 0, False) _ArrayDisplay($aResultArr, "ResultArray") ; *** just to display the array MsgBox(BitOR(4096,96), "Result :", $sSearch & " was found " & UBound($aResultArr) & " time(s)" & @CRLF) "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."
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