Add a leading Zero


I am having issues on adding a leading 0 ( Depends how many 0) if the string does now have specific length.( Lets say 12).
If the string has a length of 10 it will add 2 leading 0 in front of the string.
I am half way through it and my if/else condition is not reading the condition.
Help would be appreciated!


@sherpa24, use this


Dominic :slight_smile:


I believe something like this will also work.

stringVariable.Concat(stringVariable, “0”)

This option is dynamic for any string variable.

edit: Ah, misread your question.


I put my condition as dt_str.Length <=11 but it won’t give me an error but it is not working ( in a sense not adding leading 0 even if the number is lessthan 12)


sorry it works now, didn’t see you edited your last post, appreciate you brother!!!


Hi, I suggest using
.PadLeft(12,“0”) like suggested above, cause that will add the zeros up to a total of 12 characters, so no conditions are needed to check the length.

Also, you can just format it with .ToString.



Please refer the below tutorials,