将CSV转换为2d数组

时间:2012-07-20 22:32:13

标签: arrays applescript

我正在尝试获取一行CSV并从中提取一个项目,这里是一些代码:

tell application "Finder"
    set workingFile to (open for access outPath)
    set theContents to read workingFile using delimiter {ASCII character 13} as list
end tell

set rowTwo to item 2 of theContents as list
close access workingFile

set AppleScript's text item delimiters to {","}
set rowParts to (every text item in rowTwo) as list

display dialog rowParts

set secondItem to item 2 of rowParts


display dialog "The second item is:  " & secondItem

程序尝试执行set secondItem to item 2 of rowParts时出现此错误:

Result:
error "Can’t get item 2 of {\"Date,Day,Zimmer,Graves,Randolph,Dempsey,Hannah,DeVaughn,,GSA 0034G,GSA 0035G,48' Trailer1,48' Trailer2,53' Trailer\"}." number -1728 from item 2 of {"Date,Day,Zimmer,Graves,Randolph,Dempsey,Hannah,DeVaughn,,GSA 0034G,GSA 0035G,48' Trailer1,48' Trailer2,53' Trailer"}

有谁能告诉我为什么会发生错误?

1 个答案:

答案 0 :(得分:0)

变量rowTwo必须是字符串,而不是列表,请删除as list

as list在其他行中没用。

set theContents to read outPath using delimiter (ASCII character 13)
set rowTwo to item 2 of theContents
set AppleScript's text item delimiters to ","
set rowParts to text items of rowTwo
set secondItem to item 2 of rowParts
display dialog "The second item is:  " & secondItem