# Multiple if statements

Hello,
I have a solution for this problem, but looking to improve it or create more elegant way.

Here is the example:
I have one number which will be maximum of 6 digits.
If the number is 4 digits, I must add two 0 at the start of this document β 001234
If the number is only one digit, I must add five 0 at the start of the documen ->> 000004
I need always to have 6 digit number.

The first solution that come in my mind was this:
Create variable to store the number of digits.
Multiple IF statements where I check the length and
these IF statements will be repetitive until IF Counter = 1

The second one itβs almost the same. I think itβs not good idea, because itβs not even easy readable for the human. In every ELSE statement inside of the IF statement, I put a new IF statement for the next length.

Is there any possible way to make it better and simpler instead of recreate from the first example?

Flowcharts is the Answer for your Query

and then you make use of Flow Switch -

Please refer the below post - It has an xaml attached explaining Flow Switch.

EDIT:

• Your Number is a String, I missed that
• Iβm adding an approach for multiple IF

EDIT 2:

• Adding Dynamic padding

# Just the answer

For you workflow, just use:

`String.Format(Number, "000000")`

# Multiple If

You could create an Array {β000000β, β00000β, β0000β, β000β, β00β, β0β, ββ} and then

`DocumentNumber = myArray(Number.Length) & Number`

(as you garanty that max length is six)

# Dynamic padding

LENGTH = 6
padding = Strings.StrDup(LENGTH - Number.Length, β0β)
documentNumber = padding & Number

@Veselin_Ganchev - you can try with string.format option

like String.format(β%02dβ , number) - will add 2 zeroβs in frontβ¦

try below and check
String.format(β%β+(6-Number.Count)+βdβ , Number)

@Veselin_Ganchev
It looks like you want to react on the numbers individually

Have a look on the switch activty

From the understanding of you want to achieve that you want fill up on begin with zeros. So this can be done with the padleft function and you can avoid the nested if else

UPDATED:
And if the goal is to full up a tring to certain length with 0 so it can be done directly with padleft on the string:

1 Like

First, thanks to all people who send me proposal.
I read all of them and you give me topics to read/understand for new knowledge.

But the most simpler solution was: Number.padleft(6,CChar(β0β)).
Always fill the first digits with zero based on the max length. In this case itβs 6.
I really appreciate every single comment from this topic.

Thank you!
StaySafe!