问题
I am new to NetLogo. I have a text file that has one row of values:
ABC
CDC
BBC
I am trying to read in the first line of that file as a list of characters (e.g. [A B C]), I have been trying to use file-read-line, but it creates a string "ABC" instead.
observer> file-open "test.txt"
observer> show file-read-line
observer: "ABC"
回答1:
You will need to convert each line from a string to a list. NetLogo has no primitive to do that directly, but it's relatively simple to write a reporter that does it:
to-report string-to-list [ s ]
report ifelse-value empty? s
[ [] ]
[ fput first s string-to-list but-first s ]
end
And then:
observer> show string-to-list file-read-line
observer: ["A" "B" "C"]
来源:https://stackoverflow.com/questions/25276700/netlogo-read-in-file-as-list-of-characters