PadLeft not working

I have a string for which I want to add 0s or spaces to the left, depending on the length of the string.

I want to add two zeros to the left of the string below, but the string returned is always the same as the original string.

What am I doing wrong?

str_TicketID = “1234”

str_TicketID.PadLeft(2,CChar(“0”))

Hi @Bryan_Schmiedeler ,

You can try these two options.
texto.PadLeft(6, "0"c)
texto.PadLeft(texto.Length+2, "0"c)
UiPath.Studio_2020-10-16_14-17-13

The first argument of PadLeft() is not how many characters you want to add. It’s the totalWidth, the total length of the resulting string. PadLeft decides how many characters it needs to add, if at all. Since 2 is less than the length of your input string “1234”, it won’t add anything at all.

That worked fine. Then I don’t even have to determine the length of the string, just put 6 in that first part and the method does the rest. Perfect. Thanks.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.