Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

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
Labels (2)
12 Replies
Anonymous
Not applicable
Author

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

Just remember to replace 'row1.field1' by your value.
Anonymous
Not applicable
Author

@Tom4sz thanx for ur reply, i had already tried this one earlier and my output after applying string.format is some what like this :
0683p000009MD19.png
Anonymous
Not applicable
Author

any one ??? :0
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

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
Anonymous
Not applicable
Author

Thanks   Kumar.talend & BhanuChandar For u r kind suggestions 0683p000009MACn.png but, i have already performed using ternary expression based on length, can u suggest me using String format. 
Anonymous
Not applicable
Author

Hi Kiran,
could you pls share us your ternary expression..
Thanks,
kumar.talned
yashwanth1
Contributor
Contributor

Thanks bhanu chandar
Anonymous
Not applicable
Author

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:
0683p000009MD72.png