Skip to main content
Announcements
SYSTEM MAINTENANCE: Thurs., Sept. 19, 1 AM ET, Platform will be unavailable for approx. 60 minutes.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

tMap Pad String with Leading 0

I have been wrestling with this all day.  StringHandling.LPAD(row2.SAP_ID, 6, "0")  tests without error in the Expression Builder however isn't inserting the leading 0's in my field.  Any suggestions?

 

Many thanks!

Labels (3)
15 Replies
TRF
Champion II
Champion II

Strange! Did you check using tLogRow or something else? Can you share your component configuration?
Anonymous
Not applicable
Author

0683p000009Lw3J.png

TRF
Champion II
Champion II

Pad methods are unavailable from TOS 6.4.1, so I can't try but you can do what you want with:

StringHandling.RIGHT("000000" + row2.code, 6) 

It works.

 

Anonymous
Not applicable
Author

Alllllll day.........    Thank you so much!!!!!   That did it!

TRF
Champion II
Champion II

You're welcome.
Please, don't forget to mark the solution as accepted.
Kudos are also accepted.
vapukov
Master II
Master II

other solution - is add to project routines library StringUtils from Exchange (plus dependencies - Apache common-lang-2.6)

 

it include many useful function and handle null values more proper than some Talend functions

 

 * StringUtils.leftPad(null, *, *)     = null	
 * StringUtils.leftPad("", 3, 'z')     = "zzz"	
 * StringUtils.leftPad("bat", 3, 'z')  = "bat"	
 * StringUtils.leftPad("bat", 5, 'z')  = "zzbat"	
 * StringUtils.leftPad("bat", 1, 'z')  = "bat"	
 * StringUtils.leftPad("bat", -1, 'z') = "bat"	

and use it in tMap

it work

 

 

Vijay_K_N
Contributor
Contributor

i dont know how much zeros i want to add ,if the account number length is 11 than i want to load otherwise i want to add zeros prefix the account number ??how to solve this 

Anonymous
Not applicable
Author

@lli 

 

A quick solution is as shown below.

0683p000009M7ZY.png

 

0683p000009M7ew.png

 

The function used is as shown below where 11 is the length of the output string. If its less than 11, zeros will be padded to the left.

 

String.format("%1$11s", row1.data).replace(' ', '0')

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved

Vijay_K_N
Contributor
Contributor

where is the talend.format option in tmap (string handling  i am using talend 7.1)


@nthampi wrote:

@lli 

 

A quick solution is as shown below.

0683p000009M7ZY.png

 

0683p000009M7ew.png

 

The function used is as shown below where 11 is the length of the output string. If its less than 11, zeros will be padded to the left.

 

String.format("%1$11s", row1.data).replace(' ', '0')

Warm Regards,
Nikhil Thampi

Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved