02-22-2022 10:58 AM
Hi All,
Need help with the below scenario…
I have a value A341B22C01D91E80 I wanted to have this split from the end after every 3 characters and append with +
So my output should be A+341+B22+C01+D91+E80
Thanks in advance.
Solved! Go to Solution.
02-22-2022 12:02 PM
Using a mapper and assuming your input text is at the key $text
you can use the following expression to achieve your goal:
$text.split("").reverse().reduce((accum, cur) => (accum.length - accum.split("+").length +1) % 3 == 0 ? accum + "+" + cur: accum + cur).split("").reverse().join("")
02-22-2022 12:02 PM
Using a mapper and assuming your input text is at the key $text
you can use the following expression to achieve your goal:
$text.split("").reverse().reduce((accum, cur) => (accum.length - accum.split("+").length +1) % 3 == 0 ? accum + "+" + cur: accum + cur).split("").reverse().join("")
02-23-2022 01:20 AM
Thank you @bojanvelevski It worked like a charm…
The second one needs some adjustments in terms of what was required but both can be used for the requirement.
You are a RockStar.
02-22-2022 12:13 PM
Here’s another one:
sl.range(0,$str.length+1).filter(x=>x%3==0).reverse().map(z=>$str.substring(z-2,z+1)).reverse().join('+')