Jump to content

Searching an Array for Number of Instances of Elements


Recommended Posts

I'm trying to create an (I believe) _ArraySearch that will look at a 2D array

Local $avArray[6][2] = [ _
        ["07/01/16", "SubString0"], _
        ["06/15/16", "SubString1"], _
        ["07/01/16", "SubString2"], _
        ["06/24/16", "SubString3"], _
        ["07/01/16, "SubString4"], _
        ["06/30/16", "SubString5"]]

and return the number of times that a specific date is shown.

i.e.

07/01/16 = 3

06/30/16 = 1

etc.

I'm thinking:

_ArraySearch($avArray.$Value=_Now(),Column0)

But I have no idea if I'm even close.

My goal is to create a updateable field that will tell me the number of "calls" I've logged throughout the day.

Any assistance is appreciated.

 

Brendon

Link to comment
Share on other sites

Here's an example.

#include <Array.au3>
#include <MsgBoxConstants.au3>

Local $avArray[6][2] = [ _
        ["abc", "SubString0"], _
        ["x", "SubString1"], _
        ["y", "SubString2"], _
        ["z", "SubString3"], _
        ["abc", "SubString4"], _
        ["abc", "SubString5"]]

Local $search = "x"
Local $column = 0

Local $result = _ArrayFindAll($avArray, $search, Default, Default, Default, Default, $column)

If IsArray($result) Then
    _ArrayDisplay($result)
    local $count = UBound($result)
    MsgBox(64, "Count", $search & " occured " & $count & " time" & ($count > 1 ? "s" : "") & " in column " & $column & " of the array.")
Else
    MsgBox(16, "Count", $search & " was not found in column " & $column & " of the array.")
EndIf

I just hate software that says "1 times" ;) 

Edited by SadBunny
tpyo

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

And you can go the string route as well, this example includes substrings and all columns

#include <Array.au3>

Local $search = "ax"
$sColStart = 0
$sColEnd = 1

Local $avArray[6][2] = [ _
        ["abc", "SubString0"], _
        ["ax", "SubString1"], _
        ["y", "SubString2"], _
        ["z", "SubStringax"], _
        ["axc", "SubString4"], _
        ["abc", "SubString5"]]


stringreplace(_ArrayToString($avArray , "," , -1 , -1 , "," , $sColStart , $sColEnd) , $search , $search)

msgbox(0, '' , @Extended & " instance(s) of " & '"' & $search & '"')

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

1 hour ago, iamtheky said:

And you can go the string route as well, this example includes substrings and all columns

I haven't tested it but it's probably slower with that string manipulation, and if nothing else you'd have to worry about the data and/or the search string containing instances of your delimiter though.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
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
 Share

×
×
  • Create New...