Sign in to follow this  
Followers 0
jdelaney

Working with an array of arrays

5 posts in this topic

I'm using StringRegExp, with Flag = 4:

Return an array of arrays containing global matches including the full match (Perl / PHP style).

example:

#include <Array.au3>
$string = "asdf qwer zxcv" & @CRLF & "1231 4564 7897" & @CRLF & "poui lkjh mnbv"
$array = StringRegExp($string, "(?U)(\w{4,4})\s(\w{4,4})\s(\w{4,4})\s?", 4)
; only way I know how:  temp arrays
For $i = 0 To UBound($array)-1
 $tempArray = $array[$i]
 For $j = 1 To UBound($tempArray)-1
  ConsoleWrite("[i,j]:[" & $i & "," & $j & "] [value]:[" & $tempArray[$j] & "]" & @CRLF)
 Next
Next

Is there anyway to work with within the array without setting it to the $tempArray? Conceptually, something like:

For $i = 0 To UBound($array)-1
 For $j = 0 To UBound($array[$i])-1
  ConsoleWrite($array[$i].[$j])
 Next
Next

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites



jdelaney,

As far as I remember from previous discussions about this you have to extract the inner array from the outer array to access it. AutoIt does not know what is in each array element and so there is no programmatic way to access it directly. :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

jdelaney,

You could use a wrapper function along these lines:

#include <Array.au3>

$sString = "Here is a string which we will split"

Global $aArray[2] = [$sString, StringSplit($sString, " ")]

_Extract_Inner_Index($aArray[1], 2)

_ArraySort($aArray[1], 0, 1)

_Extract_Inner_Index($aArray[1], 2)

Func _Extract_Inner_Index(ByRef $avInput, $iIndex)
    MsgBox(64, "_Extract_Inner_Index", "Index [" & $iIndex & "] = " & $avInput[$iIndex])
EndFunc

It needs a lot of errorchecking code added and is not exactly elegant, but it is better than nothing. ;)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Without temp array, but using a func

#include <Array.au3>
$string = "asdf qwer zxcv" & @CRLF & "1231 4564 7897" & @CRLF & "poui lkjh mnbv"
$array = StringRegExp($string, "(?U)(\w{4,4})\s(\w{4,4})\s(\w{4,4})\s?", 4)

; only way I know how:  temp arrays
For $i = 0 To UBound($array) - 1
    _Parse($array[$i])
Next

Func _Parse(ByRef $array)
    For $j = 1 To UBound($array) - 1
        ConsoleWrite("[i,j]:[" & $i & "," & $j & "] [value]:[" & $array[$j] & "]" & @CRLF)
    Next
EndFunc   ;==>_Parse

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

Same method as M23, but without the _ArraySort().

Local $string = "asdf qwer zxcv" & @CRLF & "1231 4564 7897" & @CRLF & "poui lkjh mnbv"
Local $array = StringRegExp($string, "(?U)(\w{4,4})\s(\w{4,4})\s(\w{4,4})\s?", 4)

Local $sDisplayArrays
For $i = 0 To UBound($array) - 1
    For $j = 0 To UBound($array[$i]) - 1
        $sDisplayArrays &= "array[" & $i & "], index[" & $j & "] =" & @TAB & _ArrayValue($array[$i], $j) & @LF
    Next
Next
MsgBox(0, "Arrays Displayed", $sDisplayArrays)


Func _ArrayValue(ByRef $array, $iIndex)
    Return $array[$iIndex]
EndFunc   ;==>_ArrayValue

I really think it is easier to find a required regular expression pattern using flag 3 and returning one array of global matches than using flag 4 and entering the added complexity of dealing with arrays in an array.

Local $string = "asdf qwer zxcv" & @CRLF & "1231 4564 7897" & @CRLF & "poui lkjh mnbv"
Local $aArray = StringRegExp($string, "\w+\b", 3)
__ArrayDisplay($aArray)


; ------- Display Array --------
Func __ArrayDisplay(ByRef $array)
    Local $sArrayDisplay = "Row" & @TAB & "Col 0" & @CRLF & "------------------------" & @CRLF
    For $i = 0 To UBound($array) - 1
        $sArrayDisplay &= " [" & $i & "]" & @TAB & $array[$i] & @CRLF
    Next
    MsgBox(0, "ArrayDisplay", $sArrayDisplay)
EndFunc   ;==>__ArrayDisplay

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