if inbound is less than 6 characters zero fill to 6 char

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library if inbound is less than 6 characters zero fill to 6 char

  • Creator
    Topic
  • #50473
    Gina Borden
    Participant

    I would like to add a pre-tcl on my Copy statement in my xlate, that if this number is less than 6 characters, then add 0’s to the beginning of it until it reaches 6 characters.

    I’m not sure of the easiest way to do this.  Any help would be greatly appreciated.

    Thanks,

    Gina

Viewing 3 reply threads
  • Author
    Replies
    • #66239
      Jim Kosloskey
      Participant

      Gina,

      We have a proc we use here that I think will do what you want.

      If you want it, email me and I will send it to you.

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #66240
      Charlie Bursell
      Participant

      A proc seems like overkill to me Jim.  ðŸ™‚

      Why not simlpy  

            set num [format %06s $num]

      Note the use of s instead of d incase of empty string it would come out 000000.  If you use d the empty string would give a Tcl error.

    • #66241
      Jim Kosloskey
      Participant

      Charlie,

      Thanks – I did not know about the s instead of d.

      Always good input.

      email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

    • #66242

      Cahrlies, the “s” instead of “d” tip is very good to know. I suggest adding that to your tips and tricks presentations.

      -- Max Drown (Infor)

Viewing 3 reply threads
  • The forum ‘Tcl Library’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,126
Forums
28
Topics
9,297
Replies
34,440
Topic Tags
287
Empty Topic Tags
10