cancel
Showing results for 
Search instead for 
Did you mean: 

How to replace value in string based on othec conditions

SL12345
New Contributor III

Lets say i have a string:"FF;0545454;value1;test;01;99;;;value2;866"

how can i tell snaplogic in mapper, if third value is (value1) and value in fifth column is 01, change second value to 888 so the result will be:
"FF;888;value1;test;01;99;;;value2;866"

i tried something in mapper:

$myString.split(';')[2] == 'value1' && $myString.split(';')[4] == '01' ?

but i dont know how to finish it

 

Thank you

1 ACCEPTED SOLUTION

Aleksandar_A
Contributor III

Hello @SL12345.

You can try with the following expression in a Mapper Snap:

$myString.split(';')[2]=='value1' && $myString.split(';')[4]=='01' ? $myString.split(';').map((x,ind) => ind == 1 ? 888 : x).join(';') : $myString

Let me know if this helps you.

Regards,

Aleksandar.

View solution in original post

2 REPLIES 2

Aleksandar_A
Contributor III

Hello @SL12345.

You can try with the following expression in a Mapper Snap:

$myString.split(';')[2]=='value1' && $myString.split(';')[4]=='01' ? $myString.split(';').map((x,ind) => ind == 1 ? 888 : x).join(';') : $myString

Let me know if this helps you.

Regards,

Aleksandar.

SL12345
New Contributor III

thank you, it works 🙂