Skip to main content
March 21, 2023
Solved

Format a string value according to the requirement

  • March 21, 2023
  • 3 replies
  • 0 views

Hi,

We have a requirement to generate a document which contains some information of a user that needs to be encoded by the guidelines provided. We need to format the value in such a way that it's length remains fixed always which is provided to us. So any value which has less digits than the required number of digits should be formatted like for eg: If the input is 1250000 and the max limit is 20, then it should be encoded as 00000000000001250000.

How can we do that, thanks in advance.

    Best answer by stefanhelzle0001

    Or, even shorter:

    text(ri!value, rept("0", ri!limit))

    In case that "value" is longer or alphanumeric you might want to use this:

    concat(
      rept("0", ri!limit - len(ri!value)),
      ri!value
    )

    3 replies

    March 21, 2023

    text() function is a perfect match for you

    text(ri!value, concat(repeat(ri!limit, 0)))

    Check out text() for more details.

    stefanhelzle0001
    March 21, 2023

    Or, even shorter:

    text(ri!value, rept("0", ri!limit))

    In case that "value" is longer or alphanumeric you might want to use this:

    concat(
      rept("0", ri!limit - len(ri!value)),
      ri!value
    )

    March 22, 2023

    Cool, didn't knew about that.