string - NetLogo 字符串连接?
问题描述
我正在尝试将一些字符连接成一个字符串,然后对结果执行一些条件逻辑,但我得到的不是预期的“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
将为您提供一个列表而不是单个值。
有很多方法可以解决这个问题,但您应该首先问自己是否确定您正在查看的每个补丁上只会有一个 nukleotider。如果您确定这一点,您可以选择以下方法之一:
从返回的列表中提取第一项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)
)
好吧,最后一个可能有点矫枉过正。而且会有更多的方法来做到这一点。但希望你能找到一个适合你的...... :-)
推荐阅读
- reactjs - React 中的 SSR 缓存?
- django - 带有清晰表单的内联表单集 - 仅显示一次标签
- node.js - Google 表格 v4 API 为不包含任何元素的行返回空数组
- android - MIPI显示检测
- php - laravel 中的 Paypal 集成在获取付款状态时出错(尽管交易成功)
- css - SASS/SCSS - 身体上的颜色开关不起作用
- wordpress - WooCommerce 在他们的免费插件中禁用了自定义字段?
- firebase - 我正在尝试将 firebase 集成到我在 expo-cli 中的 react 本机应用程序中
- swift5 - 在 Xcode 12 项目中找不到 *.json 文件
- r - 如何使用 ggplot 绘制多个图形