Dos: Character count control

Solved
Ka-El Posted messages 279 Status Member -  
Ka-El Posted messages 279 Status Member -
Hello,

In a script I need to check the number of characters calculated by a variable "quant" which is the day’s ordinal (the day of the year). If the ordinal being checked is equal to 94 (for example) then I must add a "0" in front to always obtain a 3-digit result, i.e. 094 (the problem won’t occur after the ordinal "100"). How could I perform this operation in a batch script? I imagine I’ll need to use an "if"? Could you share a simple example? Thanks. K

P.S.: For an ordinal equal to "5", two "0"s must be added, i.e. "005".

2 answers

  1. jee pee Posted messages 31889 Registration date   Status Moderator Last intervention   9 982
     
    Hi,

    You add 2 zeros in front of your string:

    set quant=00%quant%

    and you extract the last 3 positions:

    set quant=%quant:~-3%

    echo %quant%

    best regards

    --
    An stranger is a friend we have not yet met.
    0
  2. Ka-El Posted messages 279 Status Member
     
    Nickel!
    That’s exactly what I needed.
    Thank you very much and have a good day :-)
    0