Forum Discussion

SL12345's avatar
SL12345
New Contributor III
2 years ago
Solved

How to replace value in string based on othec conditions

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

  • 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.

2 Replies

  • 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's avatar
      SL12345
      New Contributor III

      thank you, it works 🙂