Solved

Add leading zeros to the left of a string

  • 29 August 2022
  • 2 replies
  • 10 views

Badge +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.

icon

Best answer by david_r 29 August 2022, 09:33

View original

2 replies

Userlevel 6
Badge +32

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.

Userlevel 4

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.

Reply