String Format rows

Hi Guys, 
I have a small function to achieve i.e, I want add leading Zero's to the input which have Long as Datatype:
Output:
0000007865
0002333342
0022373461
0000236327

Input:
7865
2333342
22373461
236327
12 REPLIES
One Star

Re: String Format rows

Try this:
String.format("%10d",row1.field1) 

Just remember to replace 'row1.field1' by your value.

Re: String Format rows

@Tom4sz thanx for ur reply, i had already tried this one earlier and my output after applying string.format is some what like this :

Re: String Format rows

any one ??? :0
One Star

Re: String Format rows

Hi,
try with below one:
StringHandling.LEN(row1.Input)==9?("0"+row1.Input):
StringHandling.LEN(row1.Input)==8?("00"+row1.Input):
StringHandling.LEN(row1.Input)==7?("000"+row1.Input):
StringHandling.LEN(row1.Input)==6?("0000"+row1.Input):
StringHandling.LEN(row1.Input)==5?("00000"+row1.Input):
StringHandling.LEN(row1.Input)==4?("000000"+row1.Input):
StringHandling.LEN(row1.Input)==3?("0000000"+row1.Input):
StringHandling.LEN(row1.Input)==2?("00000000"+row1.Input):
StringHandling.LEN(row1.Input)==1?("000000000"+row1.Input):
StringHandling.LEN(row1.Input)==0?("0000000000"+row1.Input):row1.Input 
Regards,
kumar.talend
Two Stars

Re: String Format rows

Hi,
We can achieve the same thing in different ways. I thought this solution could be very precise and simple.
Use the fallowing expression:
("0000000000" +row1.Test).substring(row1.Test.length())
here row1.Test would be your input & based on the size u can increase/decrease the zeros.
-Bhanu

Re: String Format rows

Thanks  Kumar.talend & BhanuChandar For u r kind suggestions Smiley Happy but, i have already performed using ternary expression based on length, can u suggest me using String format. 
One Star

Re: String Format rows

Hi Kiran,
could you pls share us your ternary expression..
Thanks,
kumar.talned
One Star

Re: String Format rows

Thanks bhanu chandar

Re: String Format rows

Earlier I tried this one:
StringHandling.LEN(Var.var1)==5?"00000"+Var.var1:
StringHandling.LEN(Var.var1)==6?"0000"+Var.var1:
StringHandling.LEN(Var.var1)==8?"00"+Var.var1:
Var.var1 
Output:

Re: String Format rows

Thanks bhanu chandar Smiley Happy

Re: String Format rows

this one is simple which was suggested by bhanuchandar: Var.var1!=""?("0000000000"+Var.var1 ).substring(Var.var1.length()):""   
Output:
Five Stars

Re: String Format rows

Good solution bhanu.