viewpoint-particle

Author Topic: Retain leading zeros  (Read 2511 times)

twb

  • Newbie
  • *
  • Posts: 8
Retain leading zeros
« on: August 05, 2013, 12:02:38 pm »
I searched the manual and the forums for an answer but must not be using the correct search terms.

I'm building a string of data to pass to a program called with FTP using rcmd in my FTP script.  Building a parameter string manually and calling the program works fine.  For production I will be building the string from array values. The issue I am having is one of the values is a count of errors.   In the example string below "dtlcnt" is my count of errors. I am wanting a 2 digit value and need to retain the leading zero. '07', not '7 '.

dtlcnt is the number of array elements, up to 99.

newString1 = StrInsert(newString1,dtlcnt,' ',12,2)

Is there a way to define an edit code so the leading zero is not suppressed? 

Coding the following works but to me isn't ideal:

      if dtlcnt < 10
         newString1 = StrInsert(newString1,'0',' ',12,1)
         newString1 = StrInsert(newString1,dtlcnt,' ',13,1)
      else;
         newString1 = StrInsert(newString1,dtlcnt,' ',12,2)
      endif

Thank you,
Tom


JTaylor

  • Pundit
  • *****
  • Posts: 1085
    • Data & Stuff Inc.
Re: Retain leading zeros
« Reply #1 on: August 05, 2013, 12:43:27 pm »
Take a look at StrFixLeft().

Jim

twb

  • Newbie
  • *
  • Posts: 8
Re: Retain leading zeros
« Reply #2 on: August 05, 2013, 12:53:40 pm »
Thank you Jim.

The following worked:

newString1 = StrInsert(newString1,StrFixLeft(dtlcnt, "0", 2),' ',12,2)