![](/img/trans.png)
[英]how to iterate a string array and concat elements together in javascript?
[英]Concat 2 string together in rego
如何连接 2 个字符串?
在这里,我尝试定义一个 function 将“f”连接到提供的字符串的末尾:
concat_f(bar) = output{
item := ["f"]
x := concat(bar, item)
output := x
}
但是当我尝试使用它时(将bar
作为"123"
传递):
hello {
x := input.bar
y := concat_f(x)
y == "123f"
}
我知道hello
等于false
这是为什么? 以及如何正确连接字符串?
因为它检查条件 y == "123f" 并报告错误。
您的项目是数组,输入是字符串。 我通常转换为数组或设置进行连接,字符串我觉得很难,可能我也是新的
https://play.openpolicyagent.org/p/sETVNU37B8
package play
concat_f(bar) = output{
item := ["fine"]
out := array.concat(bar, item)
x := concat("", out)
output := x
}
hello = y {
x := input.bar
y := concat_f(x)
#y == "123fine"
}
您可以使用concat
为给定的输入栏添加"f"
后缀,并使用空字符串作为分隔符。
这里定义为简单的 function:
concat_f(bar) = concat("", [bar, "f"])
然后concat_f("123")
将返回"123f"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.