Skip to main content
Solved

Format String with leading zeros

  • April 11, 2022
  • 4 replies
  • 1026 views

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.

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.

4 replies

danilo_fme
Celebrity
Forum|alt.badge.img+51
  • Celebrity
  • 2077 replies
  • April 11, 2022

Hi @Hani Draidi​ 

 

I suggest you to use the transformer StringConcatenator:

 

String 

 

Thanks in Advance,

Danilo


hanidraidi
  • Author
  • 2 replies
  • April 11, 2022

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+60
  • 2938 replies
  • 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
  • 2 replies
  • 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.

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

Appreciated!