I need help on Dataweave 2.0 code for the output which I am receiving input as below:
Input - 0000000123456789
Output should be - 0123456789
How can I fix this?
I need help on Dataweave 2.0 code for the output which I am receiving input as below:
Input - 0000000123456789
Output should be - 0123456789
How can I fix this?
You can try the following DataWeave expression:
%dw 2.0
output application/json
var value = "0000000123456789"
fun getLastChars(str, len) =
if (str != null and sizeOf(str) >= len)
value[(sizeOf(str) - len) to (sizeOf(str)-1)]
else str
---
{
val: getLastChars(value, 10)
}
If the length of your string is not going to change just do this :
%dw 2.0
output application/json
var myString = "0000000123456789"
---
myString[6 to 15]
Just as another interesting way to do it, though as a reusable function olamiral's answer is probably the way to go.
%dw 2.0
output application/json
import withMaxSize from dw::core::Strings
---
(payload[-1 to 1] withMaxSize 10)[-1 to 1]