Skip to main content

TalendStringUtil routine

The TalendStringUtil routine contains only one function DECODE that allows you to search a value in a port.

You can access the function by double-clicking the TalendStringUtil node under the system routines folder in the Repository tree view.

Function

Description

Syntax

DECODE

Searches a port for a value you specify. If the function finds the value, it returns a result value, which you define. You can build an unlimited number of searches within a DECODE function.

TalendStringUtil.DECODE(value, defaultValue, search1, result1[, search2, result2]...)

  • value: the value you want to search.

  • defaultValue: the value you want to return if the search does not find a matching value. The default value can be set to null.

  • search: the value for which you want to search. The search value must have the same datatype as the value argument.

  • result: the value you want to return if the search finds a matching value.

Below is an example of how to use the DECODE function with a tJava component. You need to add a tJava component to a new Job, then enter the following code, which will search the value for 10, in the Code field on the Basic settings view of the tJava component.

TalendStringUtil<Integer,String> example = new TalendStringUtil<Integer,String>();
System.out.println(example.DECODE(10, "error", 5, "five", 10, "ten", 15, "fifteen", 20, "twenty"));

Note that you need to create a new object of the TalendStringUtil type, and better to use generic type to constrain the input data, then use the object to call the DECODE routine.

Press F6 to run the Job. It will return ten, which is the result of the value 10.

Did this page help you?

If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!