我使用下面的脚本从.csv文件导入。问题是我想要替换文件中的字符串或空(例如#NULL!和空单元格)。如果我使用如下条件:
if value = "#NULL!" or value = "" [print "Replace value"]
什么都没发生。我认为这是编码的问题,或者netlogo还有其他一些“功能”。我还尝试用记事本保存csv以摆脱Excel“additons”。
CSV导入代码
to openFile
file-open "/import/import.csv"
set fileList []
while [not file-at-end?] [
set csv file-read-line
set csv word csv "," ; add comma for loop termination
let mylist [] ; list of values
while [not empty? csv] [
let $x position "," csv
let $item substring csv 0 $x ; extract item
carefully [set $item read-from-string $item][] ; convert if number
set mylist lput $item mylist ; append to list
set csv substring csv ($x + 1) length csv ; remove item and comma
]
set fileList lput mylist fileList
]
;show fileList
file-close
end