2016-08-18 81 views
0

尝试在自动热键中读取CSV文件,并逐行将行拆分为“,”以提取每行的最后两列。目前只是试图让字符串拆分成数组。我可以用行 MsgBox, A_LoopReadLine打印每行,但不能在变量内分割字符串。将数组中的字符串拆分为数组autohotkey

已经尝试了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],",") 
+0

相关:[?我如何劈AutoHotkey的制表符分隔字符串(https://stackoverflow.com/q/45620437/3357935) –

回答

1

试图读取线自动热键一个CSV文件,并通过行“”分裂 线拉出每一行的最后两列。

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

这将存储您的CSV文件格式MyArray[row][column]。 E.g访问第二个项目在第五行:MyArray[5][2]

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

以上将删除每一行所有,但最后两个项目。


文档:

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()返回对象,数组所以下面的行你试图在MsgBox中显示对象,这是不允许的。

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

例如,这将工作:

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