【问题标题】:Dataweave - String array remove square bracketsDataweave - 字符串数组删除方括号
【发布时间】:2018-11-14 22:16:10
【问题描述】:

我得到了这个字符串数组

["HELLO","WORLD"]

我想输出相同但不带方括号:

"HELLO","WORLD"

如何在 Mule 中用 Dataweave 替换或转换它?

【问题讨论】:

    标签: arrays mule transform dataweave


    【解决方案1】:

    可能的解决方案(感谢 cmets 中的@jerney)

    使用索引操作:

    %dw 1.0
    %output application/java
    
    %var input = "[\"HELLO\", \"WORLD\"]"
    ---
    input[1..-2]
    

    使用正则表达式:

    %dw 1.0
    %output application/java
    
    %var input = "[\"HELLO\", \"WORLD\"]"
    ---
    input replace /^\[|\]$/ with ""
    

    使用简单替换:

    %dw 1.0
    %output application/java
    
    %var input = "[\"HELLO\", \"WORLD\"]"
    ---
    input replace "[" with "" replace "]" with ""
    

    【讨论】:

    • 如果您需要更安全一点(避免替换整个字符串的[]),input[1 to -2] 也是一个选项,假设input 是一个字符串。
    • Regex 也是一种选择,因此您无需调用两次replaceinput replace /^\[|\]$/ with "",但它似乎更神秘一些。
    • 我更喜欢这两种解决方案,哈哈。我会更新答案,以免他们迷失在 cmets 中。
    猜你喜欢
    • 2017-09-24
    • 2011-11-03
    • 2017-10-31
    • 1970-01-01
    • 2012-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多