Jump to content

Recommended Posts

Posted (edited)

Hello. I'm just learning Python at school but I like to use AutoIt also, I can't get past one thing though.
Lets say I have some information about chars and their ASCII value but I don't have it sorted. The idea is that information about every char is stored in its own subarray. How can I extract the value of lets say char 2 which should return something like this?

["a", 97]


As in python you just write array[1] and it returns the second subarray, but how do you do this in AutoIt? Thanks!

$array = [["b", 98], ["a", 97], ["c", 99]]

I already read some topics about this but the solutions seemed very complicated but there should be an easy solution for this as this is a basic operation (I suppose)

Edited by knuxfighter
  • Moderators
Posted (edited)

knuxfighter,

It is not that difficult:

#include <Array.au3>

Global $aArray2D[][] = [["b", 98], ["a", 97], ["c", 99]]

; Extract the data for element [1]
$aExtract = _ArrayExtract($aArray2D, 1, 1)

_ArrayDisplay($aExtract, "", Default, 8)

Please ask if you have any questions.

M23

Edited by Melba23
27k

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 2/2/2017 at 7:43 PM, Melba23 said:

knuxfighter,

It is not that difficult:

#include <Array.au3>

Global $aArray2D[][] = [["b", 98], ["a", 97], ["c", 99]]

; Extract the data for element [1]
$aExtract = _ArrayExtract($aArray2D, 1, 1)

_ArrayDisplay($aExtract, "", Default, 8)

Please ask if you have any questions.

M23

Expand  

Thank you. I have one more question. How do I add ["d", 100] to the end of the array? Probably I have to resize the array to size+1 as none of the following seem to work:

$aArray2D[3][0] = "d"
$aArray2D[3][1] = 100

$aArray2D[3] = ["d", 100]

_ArrayAdd($aArray2D, ["d", 100])

_ArrayAdd($aArray2D[3][0], "d")
_ArrayAdd($aArray2D[3][1], 100)



Or is there any simpler solution? Thank you again :)

  • Moderators
Posted

knuxfighter,

#include <Array.au3>

Global $aArray2D[][] = [["b", 98], ["a", 97], ["c", 99]]

_ArrayAdd($aArray2D, "d|100")

_ArrayDisplay($aArray2D, "", Default, 8)

Look in the remarks section of the help file page for _ArrayAdd to see the correct syntax for adding elements to arrays.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

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
×
×
  • Create New...