I've also tried here to shift an array to start at key -5 or 6, although to shift it upwards appears to be more difficult, if anyone can better the script below, although I did find a reasonably good solution, if a StrRept function is used.
Code: Select all
q:: ;0-based array, shift key numbers by an offset
Loop, 4
{
(A_Index = 1) && (oArray := StrSplit("zero,one,two,three,four,five", ",")).RemoveAt(0)
(A_Index = 2) && (oArray := StrSplit("minus five,minus four,minus three,minus two,minus one,zero", ",")).RemoveAt(-5,6)
if (A_Index = 3)
{
oArray := StrSplit("six,seven,eight,nine,ten", ",")
Loop, 5
oArray.InsertAt(1, ""), oArray.Delete(1)
}
(A_Index = 4) && ((oArray := StrSplit("six,seven,eight,nine,ten", ",")).InsertAt(1, StrSplit(StrRept(",",5))*), oArray.Delete(1, 5))
vOutput := ""
for vKey, vValue in oArray
vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput
}
oArray := ""
return
;==================================================
StrRept(vText, vNum)
{
return StrReplace(Format("{:" vNum "}","")," ",vText)
;return StrReplace(Format("{:0" vNum "}",0),0,vText)
}
[EDIT:] I just thought of a simpler more general method, although the earlier methods can be useful, if you want to modify an existing array.
Code: Select all
q:: ;0-based array, shift key numbers by an offset
Loop, 3
{
(A_Index = 1) && (oArray := {}).InsertAt(0, StrSplit("zero,one,two,three,four,five", ",")*)
(A_Index = 2) && (oArray := {}).InsertAt(-5, StrSplit("minus five,minus four,minus three,minus two,minus one,zero", ",")*)
(A_Index = 3) && (oArray := {}).InsertAt(6, StrSplit("six,seven,eight,nine,ten", ",")*)
vOutput := ""
for vKey, vValue in oArray
vOutput .= vKey " " vValue "`r`n"
MsgBox, % vOutput
}
oArray := ""
return
[EDIT:] Re. a 1-based index, so maybe I agree with the dog.
« What's on your mind? » - Page 168 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 27#p156027