How to output the final x number of characters in a variable-length string

Scenario: You have to output the final three characters of a field value coming from a datastream however, the string of the value can vary from 3 characters on-wards, i.e.  the value is never fixed.

    1. Open the process.
    2. Add the variable version of the field you wish to format.
    3. Right-click on the variable and select Edit Script…
    4. Insert the following code:

    //Places the length of the string into variable $a

    // Subtracts 2 from the length
    $b = num($a) – 2;

    //Variable $1MWWBANO takes the substring of its value based on the subtracted //variable $b as the position and ‘3’ as the number of subsequent places that are //outputted
    $1MWWBANO = substr($1MWWBANO,$b,3);

    1. Click OK.

    Export, deploy and test!

    • If the field value is 1234567 you will output 567
    • IF the field value is 123 you will output 123
    • If the field value is 34-4533345689 you will output 689


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s