在Netlogo中读取文件时忽略空行的最简单方法

在Netlogo中读取文件时忽略空行的最简单方法

问题描述:

我有一些代码可以读取名称文件并创建列表:

I have some code that reads a file of names and creates a list:

let who-file-name "world-health-field-surveillance.csv"
let who-file-name-dict csv:from-file who-file-name
let who-file-names sort [who] of names
let index 1 ;not 0, this removes the header in the csv

repeat length who-file-names [
  file-open "world-health-field-surveillance.csv"
  if file-at-end? [stop]
  let entry (item 0 (item index who-file-name-dict))
  if entry = "\n" [stop]

文件可能以一些空行结尾,或者文件的名称可能用换行符分隔,如下所示:

The file might end with some blank lines or its possible the file has names separated by a newline, like so:

Allman
Atkinson

Behlendorf 

我想忽略任何仅包含空格的行.

我的示例代码不起作用. 如何在netlogo中做到这一点?

I want to ignore any lines that contain only whitespace.

My sample code doesn't work. How could I do this in netlogo?

您到底想做什么?如果我有一个看起来像这样的csv文件:

What are you trying to do, exactly? If I have a csv file that looks like this:

如果我运行以下代码:

extensions [ csv ]

to setup
  ca
  let example csv:from-file "example_names.csv"
  print example
  reset-ticks
end

我得到的列表输出如下:

I get a list output that looks like:

[[Allman] [Atkinson] [Behlendorf] [Belnich] [Cravit] [Court]]

这不是您所追求的吗?如果您只需要一个单级列表,则可以

Is that not what you're after? If you need just a single-level list, you can do

print reduce sentence example

获得

[Allman Atkinson Behlendorf Belnich Cravit Court]