String padding in a Transform


#1

I have 2 fields as input that I want to concatenate, one string and one integer:
f1,f2
0A,1
0J,10
CV,100
etc.

I want the concatenated result to be fixed length, which means I need to pad the second field with ‘0’ when the length is under 3, as follows:

result
0A001
0J010
CV100
etc.

I didn’t find the appropriate function in the ExpressionEngineFunction type…
Is my only solution to created a bunch of nested ternary operators to test all possible lengths?

Thanks


#2

What is the maximum length of f2? If it is 3 you could always add ‘00’ at the front and then take the last 3 characters. substring(concat(‘00’, f2), length(concat(‘00’, f2)) - 3), length(concat(‘00’, f2))) should work.