Skip to main content
Solved

Add leading zeros to the left of a string


Forum|alt.badge.img+1

Currently imported a 'subledger' text string via Attribute Manager. Need to have leading zeros added to the left so it is always 8 characters. For example, '1046' should be '00001046'. Please advise which Transformer should I use.

 

Also another 'subledger type' text sting is dependent on the above 'subledger' field. If no subledger, it shows blank. If something in the subledger, then 'W' should show under 'subledger type'. Please advise how to achieve. Thanks.

Best answer by david_r

Concerning the leading zeros, the easiest is probably to use a StringFormatter with "08s" as the format string. But yes, you can of course also use the @padleft function as well.

View original
Did this help you find an answer to your question?

2 replies

nielsgerrits
VIP
Forum|alt.badge.img+54

The term you are looking for is Padding. Adding leading zeros can be done using the StringPadder transformer. As an alternative you can use @padleft in the AttributeCreator / AttributeManager etc.

 

The other thing you need is Conditional Values. In the AttributeCreator you can assign values based on conditions:

2022-08-29_08h35_02 

I'm not sure you want do the conditions on an attribute in the same row or a previous row. If you need a previous row you can use Adjacent Feature Attributes:

2022-08-29_08h44_17This allows you to use values in previous and/or subsequent features.


david_r
Celebrity
  • Best Answer
  • August 29, 2022

Concerning the leading zeros, the easiest is probably to use a StringFormatter with "08s" as the format string. But yes, you can of course also use the @padleft function as well.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings