Skip to main content
Solved

Add leading zeros to the left of a string

  • August 29, 2022
  • 2 replies
  • 356 views

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.

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

nielsgerrits
VIP
Forum|alt.badge.img+62

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.