Sign in to follow this  
Followers 0
GEOSoft

Just another array function

1 post in this topic

Just a quickie. This wil work with either the original _ArraySearch() or the one I posted last week'

If will return an array of all the elements of an array that contain the search criteria.

Download

#include-once
#include <array.au3>
#include <file.au3>
;===============================================================================
; Function Name:    RunExample()
; Description:        Uses _ArraySearch() to find all ocurrences of a search query between two points in an array.
; Syntax:                 _ArrayFindAll($iArray, $iQuery[, $iStart = 0[,  $iEnd = 0[, $iCaseSense = 0[, $fPartialSearch = False]]]])
; Parameter(s):    $iArray - the array to search
;                              $iQuery - the search string
;                              $iStart - the element where the search should start. Usually 0 or 1
;                              $iEnd - the element where the search should stop searching.
;                              $iCaseSense - 1 = case sensitive, 0 = not case sensitive. (default)
;                              $iPartialSearch - True =  query must match the whole element.  False = Match any portion of the element (default)
; Requirements:   #include <array.au3> and <file.au3>
; Return Value(s):   Success - Returns an array of the element numbers containing the search string
;                              Failure - Sets @Error to 1 and returns the no results message.
; Author(s):              GEOSoft (Based on _ArraySearch() by SolidSnake)
; Modifications:        
; Remarks:            If any of the optional parameters are used then the preceeding parameters must also be used
; Example(s):         Uncomment the RunExample() line below
;===============================================================================

;RunExample();<<== uncomment to run

Func RunExample()
    $File = @WindowsDir & "\setuplog.txt"
    $fQuery = "ocsetup"
    $fArray = ''
    If FileExists($File) Then
        _FileReadToArray($File, $fArray)
    Else
        MsgBox(0, 'File Error', $File & ' was not located.')
        Exit
    EndIf
    If IsArray($fArray) Then
        $Found = _ArrayFindAll($fArray, $fQuery, 0,  0, 0, True)
        If IsArray($Found) Then
            MsgBox(0, 'Elements', "It's an array with " & $Found[0] & ' elements')

            For $I = 1 To $Found[0]
                MsgBox(0, 'Values', $fArray[$Found[$I]], 3)
            Next

        Else
            MsgBox(0,'No Matches', $Found)
        EndIf
    EndIf
EndFunc  ;<==> RunExample()

Func _ArrayFindAll($iArray, $iQuery, $iStart = 0,  $iEnd = 0, $iCaseSense = 0, $fPartialSearch = False)
    Local $Rtn = ''

    While 1
        $aSrch = _ArraySearch($iArray, $iQuery, $iStart,  $iEnd, $iCaseSense, $fPartialSearch)
        If $aSrch <> -1 Then
            $Rtn &= $aSrch & '|'
            $iStart = $aSrch + 1
            If iStart >= $iEnd Then ExitLoop
        Else
            ExitLoop
        EndIf
    Wend

    If $Rtn <> '' Then
        $Rtn = StringSplit(StringTrimRight($Rtn, 1), '|')
        Return $Rtn
    Else
        Return SetError(1, 1, 'No matches to your query were found')
    EndIf
EndFunc   ;<===> _ArrayFindAll()

;;============= End of Script ============

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


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
Sign in to follow this  
Followers 0