How to output all subsequent characters following a particular character in a string

Scenario: You have to output all the subsequent characters following the ‘-‘ character of a field value coming from a datastream however, the string length 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:

    $a = $lotnumber;

    //searches string of $a for ‘-‘ and gets a position number

    //adds 1 to the ‘-‘ position number to get next position
    $c = num($b)+ 1;

    //gets substring starting at ‘next’ position
    $lotnumber = substr($lotnumber,$c);

    1. Click OK.

    Export, deploy and test!

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

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 )

Google photo

You are commenting using your Google 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 )

Connecting to %s