【问题标题】:Split String in Array into an array autohotkey将数组中的字符串拆分为数组自动热键
【发布时间】:2016-08-19 05:56:36
【问题描述】:

尝试在 Auto Hot Key 中读取 CSV 文件,并用“,”逐行分割该行以提取每行的最后两列。目前只是试图让字符串拆分成一个数组。我可以用线打印每一行 MsgBox, A_LoopReadLine 但不能拆分变量内部的字符串。

尝试过 StringSplit 和 StrSplit 但我确信语法不正确。

MyArray := Object()
Loop, read, %fileop%
{
    MyArray.Insert(A_LoopReadLine) ; Append this line to the array.
    index := 1
    MsgBox, %A_LoopReadLine%
    ;MyArray.
    ;MsgBox, % StrSplit(A_LoopReadLine ,",")
}

Loop % MyArray.Length()
    MsgBox % StrSplit(MyArray[A_Index],",")

【问题讨论】:

标签: autohotkey


【解决方案1】:

尝试在自动热键中读取 CSV 文件并逐行拆分 逐行“,”拉出每行的最后两列。

MyArray := Object()
Loop, Read, %fileop%
    MyArray[A_Index]:=StrSplit(A_LoopReadLine,",")

这将以MyArray[row][column] 格式存储您的csv 文件。例如访问第五行的第二个项目:MyArray[5][2]

for k,v in MyArray
    v.RemoveAt(1,v.Length()-2)

Above 将删除每行中除最后两项之外的所有项目。


文档:

https://autohotkey.com/docs/commands/For.htm

https://autohotkey.com/docs/objects/Object.htm#RemoveAt_v1121+

https://autohotkey.com/docs/objects/Object.htm#Length


编辑: 至于为什么你的代码不起作用。确实如此。 问题是 StrSplit() 返回 object, array 所以下面一行你试图在 MsgBox 中显示对象,这是不允许的。

MsgBox % StrSplit(MyArray[A_Index],",")

这个例子可以工作:

MsgBox % StrSplit(MyArray[A_Index],",")[1]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多