Skip to main content
Solved

Format String with leading zeros


hanidraidi

Hi,

 

How can I format a string with leading zeros (eg. seven zeros) through the "Format" string function in text editor?

For example, in attribute creator, I want to create a new attribute which takes input id field (e.g. its value 5), and I want to return 00000005.

The screenshot below better elaborates my case.

 

image.pngAny help is highly appreciated.

Hani,

Best answer by nielsgerrits

I think you want to pad a string? This can be done using 

@(PadLeft,<string>,<padlenght>,<padchar>)

your example

@PadLeft(@Value(AttributeA),8,0)

As an alternative you can use the StringPadder.

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

4 replies

danilo_fme
Evangelist
Forum|alt.badge.img+44
  • Evangelist
  • April 11, 2022

Hi @Hani Draidi​ 

 

I suggest you to use the transformer StringConcatenator:

 

String 

 

Thanks in Advance,

Danilo


hanidraidi
  • Author
  • April 11, 2022
danilo_fme wrote:

Hi @Hani Draidi​ 

 

I suggest you to use the transformer StringConcatenator:

 

String 

 

Thanks in Advance,

Danilo

Thanks for the valuable input Danilo,

This works perfectly with 1-digit number, but I need a solution that formats the string based on number of zeros (Maybe this is not elaborated in my question). For example if the number is 13, the result should be 6 zeros: 00000013


nielsgerrits
VIP
Forum|alt.badge.img+54
  • Best Answer
  • April 12, 2022

I think you want to pad a string? This can be done using 

@(PadLeft,<string>,<padlenght>,<padchar>)

your example

@PadLeft(@Value(AttributeA),8,0)

As an alternative you can use the StringPadder.


hanidraidi
  • Author
  • April 12, 2022
nielsgerrits wrote:

I think you want to pad a string? This can be done using 

@(PadLeft,<string>,<padlenght>,<padchar>)

your example

@PadLeft(@Value(AttributeA),8,0)

As an alternative you can use the StringPadder.

Many Thanks @nielsgerrits​. It exactly does what I need!

Appreciated!


Reply


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