简体   繁体   English

在 mule 4 dataweave 2.0 中使用给定字符修剪字符串

[英]Trim String with Given Character in mule 4 dataweave 2.0

Hi all I got a situation on Trimming the String ends or starts with specific characters in Mule 4大家好,我遇到了在 Mule 4 中修剪字符串以特定字符结尾或开头的情况

eg:例如:

string = "\/Hello World!\/Location\/"
Characters = "\/"

Output:输出:

result = "Hello World!\/Location"

and in mule 4 In built trim only accepting String and removes only spaces on starting, ending of the String并且在 mule 4 中内置修剪只接受字符串并仅删除字符串开头和结尾的空格

is there any built in function that can solve my problem是否有任何内置功能可以解决我的问题

Tried with this Function it may work but if any inbuit function availiabe please let me know尝试使用此功能它可能会工作,但如果有任何 inbuit 功能可用,请告诉我

fun trim(str:String,chr:String = " ",size : Number = -1 )= 
do
{
    var siz= if(size == -1) sizeOf(str) else size
    var fs=str[(if(str startsWith chr) sizeOf(chr) else 0) to -1] default ""
    var bs=fs[0 to -( if(str endsWith chr) sizeOf(chr) + 1 else 1)] default ""
    var newsize=sizeOf(bs)
---
if(newsize == siz) bs else trim(bs,chr,newsize)
}
var string = "\/Hello World!\/Location\/"
var Characters = "\/"
---
trim(string,Characters)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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