select some values from an array Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1752
Joined: 16 Oct 2013, 13:53

select some values from an array

Post by Albireo » 11 May 2021, 03:24

I have an array (img) of information
Now I want to select specific information and place it in a new array (but no connection to the original array)

eg. Array1 has img.name1 and img.name2 (and so on) but also img.info1 and img.info2
I want to create an new array tmpImg (no problem)
But only the information in img.name1 is copied to tmpImg.name1. (name1, name2, name3....)
After that tmpImg.name1 (and tmpImg.name2 and so on, can be changed without affecting img.name1, name2....

(Must a temp variable be used to cut the relation to the original array?)

Code: Select all

#Singleinstance force

; Create an array
img := []
img.name1 := "tst1"
img.name2 := "tst2"
img.info1 := "info1"
img.info2 := "info2"
; - - - - - - - - - - - 
for k, v in Img
	res .= "k.: " k "`t`tv.: " v "`n"
MsgBox % "1)`n" res
; - - -   Array is created   - - - - - - - - - -


tmpImg := []
for k, v in img
{	If k = name*	; Doesn't work
		tmpImg.name1
}

res := ""
for k, v in tmpImg
	res .= "k.: " k "`t`tv.: " v "`n"
MsgBox % "2)`n" res
Albireo
Posts: 1752
Joined: 16 Oct 2013, 13:53

Re: select some values from an array

Post by Albireo » 11 May 2021, 03:37

I found a solution by myself

Code: Select all

tmpImg := []
for k, v in img
{	If inStr(k, "name")
		tmpImg[k] := v
}
Albireo
Posts: 1752
Joined: 16 Oct 2013, 13:53

Re: select some values from an array

Post by Albireo » 11 May 2021, 03:48

Thought I found the solution, but was too fast ...
It is not only name1, name2, name3 ... that exists but also name (which should not be copied.) :roll:
Albireo
Posts: 1752
Joined: 16 Oct 2013, 13:53

Re: select some values from an array  Topic is solved

Post by Albireo » 11 May 2021, 03:58

this was better :D

Code: Select all

tmpImg := []
for k, v in img
{	If regexmatch(k, "^name\d+")
		tmpImg[k] := v
}
Post Reply

Return to “Ask for Help (v1)”