NetLogo 字符串连接?
NetLogo string concatenation?
我试图将一些字符连接成一个字符串,然后对结果执行一些条件逻辑,但我得到的不是预期的 "ABC",而是“[A][B][C] ”。我怎样才能避免这种情况?
代码:
let first [basetype] of nukleotider-here with [attached]
let second [basetype] of nukleotider-on patch-at 1 0
let third [basetype] of nukleotider-on patch-at 2 0
let kombination (word first second third)
if kombination = "ABC" [set looking-for "M"]
谢谢,
帕勒
首先,first
是一个保留的 NetLogo 原语,但我假设您已经将您的代码翻译成英文以便在这里发布(谢谢!)无论如何,我假设您的变量被命名为 x1
、x2
和 x3
而不是 first
、second
和 third
.
你的问题源于 nukleotider-here
和 nukleotider-on
记者给你的是代理人集而不是单个代理人。因此,of
将为您提供一个列表而不是单个值。
有很多方法可以解决这个问题,但您应该首先问问自己,您是否确定您正在寻找的每个补丁上只会有一个核苷肽在。如果您确信这一点,您可以选择以下方法之一:
从 of
返回的列表中提取第一项:
let x1 first [basetype] of nukleotider-here with [attached]
let x2 first [basetype] of nukleotider-on patch-at 1 0
let x3 first [basetype] of nukleotider-on patch-at 2 0
从(大概)单个代理代理集中提取代理:
let x1 [basetype] of one-of nukleotider-here with [attached]
let x2 [basetype] of one-of nukleotider-on patch-at 1 0
let x3 [basetype] of one-of nukleotider-on patch-at 2 0
稍微延迟列表提取:
let x1 [basetype] of nukleotider-here with [attached]
let x2 [basetype] of nukleotider-on patch-at 1 0
let x3 [basetype] of nukleotider-on patch-at 2 0
let kombination reduce word (sentence x1 x2 x3)
只需转换成字符串列表并与之比较:
let x1 [basetype] of nukleotider-here with [attached]
let x2 [basetype] of nukleotider-on patch-at 1 0
let x3 [basetype] of nukleotider-on patch-at 2 0
let kombination (sentence x1 x2 x3)
if kombination = ["A" "B" "C"] [set looking-for "M"]
更高级:
let kombination reduce word map [ xs -> [basetype] of one-of xs ] (list
(nukleotider-here with [attached])
(nukleotider-on patch-at 1 0 )
(nukleotider-on patch-at 2 0)
)
好的,最后一个可能有点矫枉过正。而且会有更多的方法来做到这一点。但希望你能找到适合你的……:-)
我试图将一些字符连接成一个字符串,然后对结果执行一些条件逻辑,但我得到的不是预期的 "ABC",而是“[A][B][C] ”。我怎样才能避免这种情况?
代码:
let first [basetype] of nukleotider-here with [attached]
let second [basetype] of nukleotider-on patch-at 1 0
let third [basetype] of nukleotider-on patch-at 2 0
let kombination (word first second third)
if kombination = "ABC" [set looking-for "M"]
谢谢, 帕勒
首先,first
是一个保留的 NetLogo 原语,但我假设您已经将您的代码翻译成英文以便在这里发布(谢谢!)无论如何,我假设您的变量被命名为 x1
、x2
和 x3
而不是 first
、second
和 third
.
你的问题源于 nukleotider-here
和 nukleotider-on
记者给你的是代理人集而不是单个代理人。因此,of
将为您提供一个列表而不是单个值。
有很多方法可以解决这个问题,但您应该首先问问自己,您是否确定您正在寻找的每个补丁上只会有一个核苷肽在。如果您确信这一点,您可以选择以下方法之一:
从 of
返回的列表中提取第一项:
let x1 first [basetype] of nukleotider-here with [attached]
let x2 first [basetype] of nukleotider-on patch-at 1 0
let x3 first [basetype] of nukleotider-on patch-at 2 0
从(大概)单个代理代理集中提取代理:
let x1 [basetype] of one-of nukleotider-here with [attached]
let x2 [basetype] of one-of nukleotider-on patch-at 1 0
let x3 [basetype] of one-of nukleotider-on patch-at 2 0
稍微延迟列表提取:
let x1 [basetype] of nukleotider-here with [attached]
let x2 [basetype] of nukleotider-on patch-at 1 0
let x3 [basetype] of nukleotider-on patch-at 2 0
let kombination reduce word (sentence x1 x2 x3)
只需转换成字符串列表并与之比较:
let x1 [basetype] of nukleotider-here with [attached]
let x2 [basetype] of nukleotider-on patch-at 1 0
let x3 [basetype] of nukleotider-on patch-at 2 0
let kombination (sentence x1 x2 x3)
if kombination = ["A" "B" "C"] [set looking-for "M"]
更高级:
let kombination reduce word map [ xs -> [basetype] of one-of xs ] (list
(nukleotider-here with [attached])
(nukleotider-on patch-at 1 0 )
(nukleotider-on patch-at 2 0)
)
好的,最后一个可能有点矫枉过正。而且会有更多的方法来做到这一点。但希望你能找到适合你的……:-)