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!
:slight_smile:

2 Likes

@sherpa24, use this

Stringvariable.padleft(12,CChar(β€œ0”))

Regards,
Dominic :slight_smile:

20 Likes

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.
CInt(text).ToString(β€œ000000000000”)

2 Likes

Hi,

Please refer the below tutorials,

thanks,
Karthik

3 Likes