Customer Portal

How Do I Return Text at the End of a String?

Comments 1

  • Avatar
    admin
    0
    Comment actions Permalink
    Hi,

    When dealing with string fields, you might want to take a look at String Functions in the Documentation.

    In a situation like yours, I prefer the function called SPLIT. The split() function splits a string from the first argument, based on a regular expression given as the second argument (the full stop in your case). As a result, you get an array of values, and you can address each one of them using a sequence number (they are numbered starting with zero).

    Therefore, in the Reformat component, you can resolve your example situation using the following transformation:

    string[] SplitFieldArray = split($in.0.field1,"\\.");
    $out.0.field1 = SplitFieldArray[1];


    Please, note that I have "escaped" the character "." with double back-slash, because in this function the second argument is defined by regular expressions and the single full stop would then mean "any character".

    In addition, if you know exactly the length of your resulting string (for example you know that you are interested in the last 5 characters in the string), you can use a function RIGHT. The right() function returns the substring of the length specified as the second argument counted from the end of the string specified as the first argument. Your CTL2 transformation in the Reformat would then be:

    $out.0.field1 = right($in.0.field1,5);


    And it would result in HAPPY again. :)

    Please take a look and don't hesitate to ask in case you have any follow-up questions. Have a nice day, Eva

Please sign in to leave a comment.