2016-08-18 117 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]