Jump to content

How to find all index in array


Recommended Posts

This is one way you could do it:


 

#include <array.au3>

Dim $array[10] = ["6", "8", "1", "5", "9", "5", "7", "10", "1", "8"]

$index = @CRLF

For $i = 0 To 9
    If $array[$i] > 7 Then
        $index = $index & $i & @CRLF
    EndIf
Next

MsgBox(0, "", "Numbers higher than 7 are at array positions: " & $index)

 

Link to comment
Share on other sites

Not the greatest with RegExp but this should do what you want.

#include <Array.au3>
Local $aArray[20] = [10, 2, 30, 4, 50, 6, 70, 8, 90, 10, 110, 2, 130, 4, 150, 6, 170, 8, 190, 10]
Local $aFindAll = _ArrayFindAll($aArray, "\b(7|8|9|[0-9]\d+|(?!0)\d{3,})\b", 0, 0, 0, 3)
_ArrayDisplay($aFindAll)
_ArrayDisplay($aArray)

 

Link to comment
Share on other sites

Hello,

If there are negative numbers or numbers with leading zeros, that's better.

#include <Array.au3>
Local $aArray[20] = ["-010", "02", "0030", 4, 50, 6, 70, "-08", -90, 7, 110, 2, 130, 4, 150, 6, 170, -8, 190, 10]
Local $aFindAll = _ArrayFindAll($aArray, "\b(?<!-)(0*)(8|9|(?!0)\d{2,})\b", 0, 0, 0, 3)
_ArrayDisplay($aFindAll)
_ArrayDisplay($aArray)

 

 

greetings
bernd


I hacked 127.0.0.1 -> pcfred6.gif

Link to comment
Share on other sites

back to fun loops

#include <Array.au3>
Local $aArray[20] = ["-010", "02", "0030", 4, 50, 6, 8, "-08", -90, 7, "00010", 2, 130, 4, 9, 6, 170, -8, 190, 10]

If number($aArray[_ArrayMinIndex($aArray , 1)]) < 8 Then

do
    _ArrayDelete($aArray , _ArrayMinIndex($aArray , 1))
until number($aArray[_ArrayMinIndex($aArray , 1)]) > 7

EndIf

_ArrayDisplay($aArray)

 

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

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...