noob62 Posted August 28, 2015 Posted August 28, 2015 This is probably an easy solution I'm just making it complicated. Looking for some guidance on being able to search for the number of occurrences of a string in a column of an array then write the each of the occurrences and rows for that that string to a text file. Example looking for how many times Computer 1 occurs in the first column and write only the first four occurrences to the text file. Here is what I have started with:#include <Array.au3> Local $i = 0 Local $row Local $aArray[12][2] = [["Computer 1", "192.168.1.1"], _ ["Computer 2", "192.168.1.2"], _ ["Computer 1", "192.168.1.3"], _ ["Computer 3", "192.168.1.4"], _ ["Computer 3", "192.168.1.5"], _ ["Computer 1", "192.168.1.6"], _ ["Computer 1", "192.168.1.7"], _ ["Computer 4", "192.168.1.8"], _ ["Computer 5", "192.168.1.9"], _ ["Computer 6", "192.168.1.10"], _ ["Computer 7", "192.168.1.11"], _ ["Computer 1", "192.168.1.12"]] Local $aResult = _ArrayFindAll($aArray, "Computer 1") While $i < $aResult $row = $aResult[$i] FileWrite("C:\output.txt" , $row & "," & @CRLF) $i = $i + 1 WEnd _ArrayDisplay($aResult, "Items Found")
DarkwarlorD Posted August 28, 2015 Posted August 28, 2015 (edited) Hi @noob62 ... Try This:#include <Array.au3> Local $i = 0 Local $row Local $aArray[12][2] = [["Computer 1", "192.168.1.1"], _ ["Computer 2", "192.168.1.2"], _ ["Computer 1", "192.168.1.3"], _ ["Computer 3", "192.168.1.4"], _ ["Computer 3", "192.168.1.5"], _ ["Computer 1", "192.168.1.6"], _ ["Computer 1", "192.168.1.7"], _ ["Computer 4", "192.168.1.8"], _ ["Computer 5", "192.168.1.9"], _ ["Computer 6", "192.168.1.10"], _ ["Computer 7", "192.168.1.11"], _ ["Computer 1", "192.168.1.12"]] Local $aResult = _ArrayFindAll($aArray, "Computer 1") For $i = 0 To UBound($aResult) -1 FileWrite("C:\output.txt", $aResult[$i]& "," & @CRLF) Next FileWrite("C:\output.txt", "Number of Ocorrences: " & $i & @CRLF) Edited August 28, 2015 by DarkwarlorD Adjust
Gianni Posted August 28, 2015 Posted August 28, 2015 _ArrayFindAll will return an array containing the list of all the lines number where the searched string was found in the original array, not the content of that lines.you will use those "indexes" to point to the lines that contains the searched string and peek data from the original array.#include <Array.au3> Local $i = 0 Local $row Local $aArray[12][2] = [["Computer 1", "192.168.1.1"], _ ["Computer 2", "192.168.1.2"], _ ["Computer 1", "192.168.1.3"], _ ["Computer 3", "192.168.1.4"], _ ["Computer 3", "192.168.1.5"], _ ["Computer 1", "192.168.1.6"], _ ["Computer 1", "192.168.1.7"], _ ["Computer 4", "192.168.1.8"], _ ["Computer 5", "192.168.1.9"], _ ["Computer 6", "192.168.1.10"], _ ["Computer 7", "192.168.1.11"], _ ["Computer 1", "192.168.1.12"]] Local $aResult = _ArrayFindAll($aArray, "Computer 1") ; lines where "Computer1" appear in the array Local $iCount = UBound($aResult) ; <- total number of occurences While $i < $iCount ; FileWrite("C:\output.txt" , $row & "," & @CRLF) ConsoleWrite($aArray[$aResult[$i]][0] & ", " & $aArray[$aResult[$i]][1] & @CRLF) ; <--< use indexes in $aResult[$i] to point to lines in original array $i = $i + 1 WEnd ; lines where Items where Found in the original array _ArrayDisplay($aResult, "lines where Items where Found in the original array") Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
mikell Posted August 28, 2015 Posted August 28, 2015 What about the easiest route ?#include <Array.au3> Local $n = 0 Local $result Local $aArray[12][2] = [["Computer 1", "192.168.1.1"], _ ["Computer 2", "192.168.1.2"], _ ["Computer 1", "192.168.1.3"], _ ["Computer 3", "192.168.1.4"], _ ["Computer 3", "192.168.1.5"], _ ["Computer 1", "192.168.1.6"], _ ["Computer 1", "192.168.1.7"], _ ["Computer 4", "192.168.1.8"], _ ["Computer 5", "192.168.1.9"], _ ["Computer 6", "192.168.1.10"], _ ["Computer 7", "192.168.1.11"], _ ["Computer 1", "192.168.1.12"]] For $i = 0 To UBound($aArray) -1 If $aArray[$i][0] = "Computer 1" Then $n += 1 If $n < 5 Then $result &= $aArray[$i][0] & " - " & $aArray[$i][1] & @crlf EndIf Next Msgbox(0,"", $n & " occurences, the first four are :" & @crlf & $result)
noob62 Posted August 31, 2015 Author Posted August 31, 2015 (edited) Thanks for the replies that helped get me on the right track.Just adding in some other things like parsing through the whole array and showing the first four occurrences for each string in the first column then only displaying the first four instances of those occurrences.The question I have would nested IF statements be the right way to go to make sure it only gets the first four and what if there are less than 4 occurrences or greater than 4.This is what I have now but it gets stuck on the first string and only writes that out instead of the other ones. It seems like the correct way to me I'm just not connecting the dots somewhere. I added in a sort of the array with the idea that since its sorted and it is grabbing the total occurrences of each string it would just use the total found to move onto the next string avoiding looking at duplicate entriesexpandcollapse popup#include <Array.au3> Local $i = 0 Local $r = 0 Local $TotalRows, $aResult, $iCount, $aSearch Local $aArray[12][2] = [["Computer 1", "192.168.1.1"], _ ["Computer 2", "192.168.1.2"], _ ["Computer 1", "192.168.1.3"], _ ["Computer 3", "192.168.1.4"], _ ["Computer 3", "192.168.1.5"], _ ["Computer 1", "192.168.1.6"], _ ["Computer 1", "192.168.1.7"], _ ["Computer 4", "192.168.1.8"], _ ["Computer 5", "192.168.1.9"], _ ["Computer 6", "192.168.1.10"], _ ["Computer 7", "192.168.1.11"], _ ["Computer 1", "192.168.1.12"]] $TotalRows = UBound($aArray, $UBOUND_ROWS) ;Get total rows in the Array to search _ArraySort($aArray, 0, 0, 0, 0) ;Sort the Array While $i < $TotalRows $aSearch = $aArray[$i][0] ;Get string to search for $aResult = _ArrayFindAll($aArray, $aSearch) ; lines where $aSearch string appears in the array $iCount = UBound($aResult) ; <- total number of occurences While $r < $iCount ConsoleWrite($aArray[$aResult[$i]][0] & ", " & $aArray[$aResult[$i]][1] & @CRLF) ; <--< use indexes in $aResult[$i] to point to lines in original array $r = $r + 1 WEnd $i = $i + $iCount WEnd ; lines where Items where Found in the original array _ArrayDisplay($aResult, "lines where Items where Found in the original array") Edited August 31, 2015 by noob62
Gianni Posted August 31, 2015 Posted August 31, 2015 maybe something like this?#include <Array.au3> Local $iMaxOccurrences = 4 ; how many occurrences you want to consider (4 or less) Local $iMaxInstances = 4 ; how many instances you want to print (4 or less (no more than 4) Local $aArray[12][2] = [["Computer 1", "192.168.1.1"], _ ["Computer 2", "192.168.1.2"], _ ["Computer 1", "192.168.1.3"], _ ["Computer 3", "192.168.1.4"], _ ["Computer 3", "192.168.1.5"], _ ["Computer 1", "192.168.1.6"], _ ["Computer 1", "192.168.1.7"], _ ["Computer 4", "192.168.1.8"], _ ["Computer 5", "192.168.1.9"], _ ["Computer 6", "192.168.1.10"], _ ["Computer 7", "192.168.1.11"], _ ["Computer 1", "192.168.1.12"]] $aUniques = _ArrayUnique($aArray) ; $aUniques will hold only one occurrence for each hostname (1 based) For $i = 1 To $aUniques[0] ; loop all hostnames If $i > $iMaxOccurrences Then ExitLoop ; limit the loop to your choice $aSameHostNames = _ArrayFindAll($aArray, $aUniques[$i]) ; find all lines with the same HostName For $ii = 0 To UBound($aSameHostNames) - 1 ; loop all (duplicates) HostNames If $ii + 1 > $iMaxInstances Then ExitLoop ; ; limit the loop to your choice ConsoleWrite($aArray[$aSameHostNames[$ii]][0] & ", " & $aArray[$aSameHostNames[$ii]][1] & @CRLF) Next Next Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
noob62 Posted August 31, 2015 Author Posted August 31, 2015 (edited) I didn't know about _ArrayUnique that's a much better way then the way I was going about it. I do get an error when I try to run the script with _ArrayUnique "Array variable has incorrect number of subscripts or subscript dimension range exceeded." Is there a limit on the size of the array that function can handle? I'm actually getting the same error when I run the second example for _ArrayUnique #include <Array.au3> Local $aArray[6][2] = [[1, "A"], [2, "B"], [3, "C"], [1, "A"], [2, "B"], [3, "C"]] _ArrayDisplay($aArray, "2D array") ; Display the current array. Local $aArrayUnique = _ArrayUnique($aArray) ; Use default parameters to create a unique array of the first column. _ArrayDisplay($aArrayUnique, "$aArray first column") ; Display the unique array. $aArrayUnique = _ArrayUnique($aArray, 1) ; Create a unique array of the second column. _ArrayDisplay($aArrayUnique, "$aArray second column") ; Display the unique array. Edited September 1, 2015 by noob62
Gianni Posted September 1, 2015 Posted September 1, 2015 probably you are using an old version of autoit Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
jchd Posted September 1, 2015 Posted September 1, 2015 Is there a limit on the size of the array that function can handle?AutoIt array have an upper limit of 16*1024*1024 = 16777216 elements whatever dimensions combination it uses. The lower limit is 0 (empty arrays are allowed). This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
noob62 Posted September 2, 2015 Author Posted September 2, 2015 I'm am running the latest version of AutoIt, I just uninstalled AutoIt from my system and re-downloaded and installed it.It looks like the error is occurring in the actual function:C:\Program Files (x86)\AutoIt3\Include\Array.au3" (2297) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.:If IsInt($aArray[$iBase]) ThenIf IsInt(^ ERROR That's with the example 2 for UniquArray
jchd Posted September 2, 2015 Posted September 2, 2015 Already reported and fixed in the next release (see Trac ticket 3110). This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)
noob62 Posted September 2, 2015 Author Posted September 2, 2015 Hmm interesting... Any suggestions on how to achieve what I'm looking to do without UniqueArray?Would sorting the Array and searching that way still be the best approach?
kylomas Posted September 2, 2015 Posted September 2, 2015 noob62,This may interest you...expandcollapse popup#include <array.au3> ; create test array local $iSize = 500000 local $aArray[$iSize] local $st = timerinit() for $i = 0 to ubound($aArray) - 1 $aArray[$i] = 'Computer_' & stringformat('%04i',random(1,1000,1)) Next _DBG('Time to generate array') ;-------------------------------------------------------------------- $st = timerinit() _arraydisplay(_SRCH('Computer_0385', $aArray),round(timerdiff($st)/1000,4) & ' seconds') func _SRCH($sSearchString, $aTest) assign($sSearchString,'') For $i = 0 to UBound($aTest) - 1 If IsDeclared($aTest[$i]) Then Assign($sSearchString, Eval($sSearchString) & $i & ',') Next return ( eval($sSearchString) ? stringsplit(eval($sSearchString),',') : 0 ) endfunc func _DBG($str) ConsoleWrite(stringformat('!\t%-50s = %2.4f seconds',$str,timerdiff($st)/1000) & @CRLF) endfunckylomas Gianni 1 Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
kylomas Posted September 2, 2015 Posted September 2, 2015 (edited) noob62,Your original code was not that far off...#include <Array.au3> filedelete("C:\output.txt") Local $aArray[12][2] = [["Computer 1", "192.168.1.1"], _ ["Computer 2", "192.168.1.2"], _ ["Computer 1", "192.168.1.3"], _ ["Computer 3", "192.168.1.4"], _ ["Computer 3", "192.168.1.5"], _ ["Computer 1", "192.168.1.6"], _ ["Computer 1", "192.168.1.7"], _ ["Computer 4", "192.168.1.8"], _ ["Computer 1", "192.168.1.9"], _ ["Computer 6", "192.168.1.10"], _ ["Computer 7", "192.168.1.11"], _ ["Computer 1", "192.168.1.12"]] Local $aResult = _ArrayFindAll($aArray, "Computer 1") for $i = 1 to ubound($aResult) - 1 if $i > 4 then exitloop FileWrite("C:\output.txt" , 'Row = ' & $aResult[$i] & ' column 1 = ' & $aArray[$aResult[$i]][0] & ' column 2 = ' & $aArray[$aResult[$i]][1] & @CRLF) next shellexecute("C:\output.txt")kylomas Edited September 2, 2015 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
Gianni Posted September 2, 2015 Posted September 2, 2015 noob62,This may interest you...@kilomas Nice snippet! I like it..... this is an interesting replacement for the _ArrayFindAll() function, but I think that OP has a problem with the _ArrayUnique() function, not _ArrayFindAll(). Also, what you proposed in post #14 is a bit different from what OP is asking, You find the first 4 occurences of a searched item, while OP need the first 4 occurences of the first 4 items... Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
noob62 Posted September 2, 2015 Author Posted September 2, 2015 Thanks for the reply on a workaround but i'm trying to do the following:Get the first 4 occurrences of a each string in column 1 in the array and write those to a file but, have a way to work through if there is only one instance or two of a string write those to the file since they are less than 4 and avoid searching for items that have already been searched.the previous post #5 is what I think I have to work with since UniqueArray isn't working so it would be:Sort the ArrayGet the first stringget total count of string in arraywrite the first fouri + total count for the string which would go to the next string avoiding looking for duplicates
iamtheky Posted September 2, 2015 Posted September 2, 2015 This may be a little slow as it does not eliminate items it has already checked, but i think it worksLocal $aArray[12][2] = [["Computer 1", "192.168.1.1"], _ ["Computer 2", "192.168.1.2"], _ ["Computer 1", "192.168.1.3"], _ ["Computer 3", "192.168.1.4"], _ ["Computer 3", "192.168.1.5"], _ ["Computer 1", "192.168.1.6"], _ ["Computer 1", "192.168.1.7"], _ ["Computer 3", "192.168.1.8"], _ ["Computer 1", "192.168.1.9"], _ ["Computer 3", "192.168.1.10"], _ ["Computer 3", "192.168.1.11"], _ ["Computer 1", "192.168.1.12"]] local $sOut = "" For $i = 0 to ubound($aArray) - 1 $sOut &= $aArray[$i][0] & "=" $sOut &= $aArray[$i][1] & "," Next for $i = 0 to ubound($aArray) - 1 $sOut = stringregexpreplace($sOut , $aArray[$i][0] , "REPLACE" , 4) $sOut = stringregexpreplace($sOut , $aArray[$i][0] & "=.*?," , "") $sOut = stringregexpreplace($sOut , "REPLACE" , $aArray[$i][0]) next msgbox(0, '' , stringreplace($sOut , "," , @LF)) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
kylomas Posted September 3, 2015 Posted September 3, 2015 @Chimp - Thanks, I see we changed the target in post #5...my fault for not reading it.Another cut at it...expandcollapse popup#include <Array.au3> filedelete("C:\output.txt") Local $aArray[12][2] = [["Computer 1", "192.168.1.1"], _ ["Computer 2", "192.168.1.2"], _ ["Computer 1", "192.168.1.3"], _ ["Computer 3", "192.168.1.4"], _ ["Computer 3", "192.168.1.5"], _ ["Computer 1", "192.168.1.6"], _ ["Computer 1", "192.168.1.7"], _ ["Computer 4", "192.168.1.8"], _ ["Computer 1", "192.168.1.9"], _ ["Computer 6", "192.168.1.10"], _ ["Computer 7", "192.168.1.11"], _ ["Computer 1", "192.168.1.12"]] Local $cnt, $tmp, $sOut, $st = timerinit() for $i = 0 to ubound($aArray) - 1 if $aArray[$i][0] = '' then ContinueLoop $tmp = $aArray[$i][0] $sOut &= $aArray[$i][0] & @CRLF & @tab & $aArray[$i][1] & @CRLF $aArray[$i][0] = '' $cnt = 1 for $j = 0 to ubound($aArray) - 1 if $aArray[$j][0] = '' then ContinueLoop if $aArray[$j][0] = $tmp then if $cnt < 4 then $sOut &= @tab & $aArray[$j][1] & @CRLF $cnt += 1 endif $aArray[$j][0] = '' endif next next ConsoleWrite(timerdiff($st)/1000 & @CRLF) filewrite("C:\output.txt", $sOut) shellexecute("C:\output.txt")kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill
noob62 Posted September 3, 2015 Author Posted September 3, 2015 (edited) I got it to work with out picking duplicates and go through the whole Array, let me know what you think:expandcollapse popup#include <Array.au3> Local $i = 0 Local $TotalRows, $aResult, $iCount, $aSearch Local $aArray[12][2] = [["Computer 1", "192.168.1.1"], _ ["Computer 2", "192.168.1.2"], _ ["Computer 1", "192.168.1.3"], _ ["Computer 3", "192.168.1.4"], _ ["Computer 3", "192.168.1.5"], _ ["Computer 1", "192.168.1.6"], _ ["Computer 1", "192.168.1.7"], _ ["Computer 4", "192.168.1.8"], _ ["Computer 5", "192.168.1.9"], _ ["Computer 6", "192.168.1.10"], _ ["Computer 7", "192.168.1.11"], _ ["Computer 1", "192.168.1.12"]] $TotalRows = UBound($aArray, $UBOUND_ROWS) ;Get total rows in the Array to search _ArraySort($aArray, 0, 0, 0, 0) ;Sort the Array While $i < $TotalRows $aSearch = $aArray[$i][0] ;Get string to search for $aResult = _ArrayFindAll($aArray, $aSearch) ; lines where $aSearch string appears in the array $iCount = UBound($aResult) ; <- total number of occurences Local $r = 0 While $r < $iCount ConsoleWrite($aArray[$aResult[$r]][0] & ", " & $aArray[$aResult[$r]][1] & @CRLF) ; <--< use indexes in $aResult[$i] to point to lines in original array $r = $r + 1 WEnd $i = $i + $iCount WEnd ; lines where Items where Found in the original array _ArrayDisplay($aResult, "lines where Items where Found in the original array") Now just looking at how to limit the output to a speciific number. I nested some If and While statements in there but I can't get it to work properly any ideas:expandcollapse popup#include <Array.au3> Local $i = 0 Local $TotalRows, $aResult, $iCount, $aSearch Local $Limit = 4 Local $aArray[12][2] = [["Computer 1", "192.168.1.1"], _ ["Computer 2", "192.168.1.2"], _ ["Computer 1", "192.168.1.3"], _ ["Computer 3", "192.168.1.4"], _ ["Computer 3", "192.168.1.5"], _ ["Computer 1", "192.168.1.6"], _ ["Computer 1", "192.168.1.7"], _ ["Computer 4", "192.168.1.8"], _ ["Computer 5", "192.168.1.9"], _ ["Computer 6", "192.168.1.10"], _ ["Computer 7", "192.168.1.11"], _ ["Computer 1", "192.168.1.12"]] $TotalRows = UBound($aArray, $UBOUND_ROWS) ;Get total rows in the Array to search _ArraySort($aArray, 0, 0, 0, 0) ;Sort the Array While $i < $TotalRows $aSearch = $aArray[$i][0] ;Get string to search for $aResult = _ArrayFindAll($aArray, $aSearch) ; lines where $aSearch string appears in the array $iCount = UBound($aResult) ; <- total number of occurences Local $r = 0 If $Limit > $iCount Then While $r < $iCount ConsoleWrite($aArray[$aResult[$r]][0] & ", " & $aArray[$aResult[$r]][1] & @CRLF) ; <--< use indexes in $aResult[$i] to point to lines in original array $r = $r + 1 WEnd ElseIf $Limit < $iCount Then While $r < $iCount & $r <> $Limit ConsoleWrite($aArray[$aResult[$r]][0] & ", " & $aArray[$aResult[$r]][1] & @CRLF) ; <--< use indexes in $aResult[$i] to point to lines in original array $r = $r + 1 WEnd EndIf $i = $i + $iCount WEnd Edited September 3, 2015 by noob62
noob62 Posted September 3, 2015 Author Posted September 3, 2015 I got it figured out now, thanks for all the help and guidance. Below is what I have that works: expandcollapse popup#include <Array.au3> Local $i = 0 Local $TotalRows, $aResult, $iCount, $aSearch Local $Limit = 4 Local $aArray[12][2] = [["Computer 1", "192.168.1.1"], _ ["Computer 2", "192.168.1.2"], _ ["Computer 1", "192.168.1.3"], _ ["Computer 3", "192.168.1.4"], _ ["Computer 3", "192.168.1.5"], _ ["Computer 1", "192.168.1.6"], _ ["Computer 1", "192.168.1.7"], _ ["Computer 4", "192.168.1.8"], _ ["Computer 5", "192.168.1.9"], _ ["Computer 6", "192.168.1.10"], _ ["Computer 7", "192.168.1.11"], _ ["Computer 1", "192.168.1.12"]] $TotalRows = UBound($aArray, $UBOUND_ROWS) ;Get total rows in the Array to search _ArraySort($aArray, 0, 0, 0, 0) ;Sort the Array While $i < $TotalRows $aSearch = $aArray[$i][0] ;Get string to search for $aResult = _ArrayFindAll($aArray, $aSearch) ; lines where $aSearch string appears in the array $iCount = UBound($aResult) ; <- total number of occurences Local $r = 0 If $Limit > $iCount Then ;If occurances are less then the specified limit While $r < $iCount ConsoleWrite($aArray[$aResult[$r]][0] & ", " & $aArray[$aResult[$r]][1] & @CRLF) ; <--< use indexes in $aResult[$i] to point to lines in original array $r = $r + 1 WEnd Else ;If the number of occurances are greater then the specified limit While $r < $Limit ConsoleWrite($aArray[$aResult[$r]][0] & ", " & $aArray[$aResult[$r]][1] & @CRLF) ; <--< use indexes in $aResult[$i] to point to lines in original array $r = $r + 1 WEnd EndIf $i = $i + $iCount WEnd
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