繁体   English   中英

Concat 2 在 rego 中串在一起

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM