NetLogo read in file as list of characters

泪湿孤枕 提交于 2019-12-24 03:56:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!