To pad a String in Talend Open Studio, use the StringUtils.rightPad, leftPad, center, or repeat functions. This example uses rightPad to add 0s to the end of a String if it's shorter than 8 characters
AAAAADDD -> AAAAADDD
CCCC -> CCCC0000
BBBB0000 -> BBBB00000
The following job sets up a list in a tForeach component of the test input data. A tIterateToFlow component applies a Commons Lang StringUtils.rightPad function. The result is output to a tLogRow. The results of the run and call to the StringUtils function are below.
Application of rightPad() in a tIterateToFlow |
Commons Lang is a widely-used JAR available in Talend Open Studio. Several versions are installed with Talend 5. I use 2.6. The following shows the Basic Settings configuration for tLibraryLoad.
Adding Commons Lang 2.6 to a Project |
tForEach
I test Java expressions on a range of values from a tForEach rather than creating input files or records. Here is the configuration used for the tForeach.
Input for Job in tForeach |
:-) tnks
ReplyDeleteIt will not works??!!!
ReplyDeleteIf I write in expression rightPad("AAAA0000",8,"0") then I get "Exception in thread "main" java.lang.Error: Unresolved compilation problem: "
where is the mistake?
Hi,
DeleteThis post is from an older version. I don't work with Talend anymore, so I'm not sure what this would look like in the newer version. Check for an important "import static" line that needs to be added to the tLibraryLoad component. This let's you leave off the StringUtils. prefix.