如何在AutoHotkey中打印数组?

时间:2017-09-01 14:56:08

标签: arrays autohotkey

我在AutoHotkey中有一组数组,我想将它们显示为调试字符串。

strArray := ["Alice", "Mary", "Bob"] ; 1D array
strArray2D := [[1,2,3], [4,5,6]]     ; 2D array

在Java,Javascript和AutoIt中我可以使用内置的toString()函数来完成此任务。

strArray.toString();            // JavaScript: "Alice,Mary,Bob"
Arrays.toString(strArray);      // Java:       "[Alice, Mary, Bob]"
_ArrayToString($strArray, ", ")  ; AutoIt:     "Alice, Mary, Bob"

AHK的开发人员lexikos已经提出了一个用于显示数组will not be added anytime soon的内置函数,以及我在网上找到的大多数解决方案seem fairly complex

如何在AutoHotkey中打印数组?

1 个答案:

答案 0 :(得分:4)

这会将1维和2维数组转换为字符串

F2:: MsgBox % join(["Alice", "Mary", "Bob"])
F3:: MsgBox % join2D([[1,2,3], [4,5,6]])


join( strArray )
{
  s := ""
  for i,v in strArray
    s .= ", " . v
  return substr(s, 3)
}

join2D( strArray2D )
{
  s := ""
  for i,array in strArray2D
    s .= ", [" . join(array) . "]"
  return substr(s, 3)
}

enter image description here