Printer Version Table of Contents Project Home Page
.FUNCTION....: Substr (Substring) Function
.CATEGORY....: functions
This function returns a substring of the string supplied in the /Q parm, starting in the column supplied in the /A parm, for a length supplied in the /B parm.

The start column specified in the /A parm may be a negative number; if it is, then the start column is calculated from the end of the string rather than from the beginning. This feature makes it easy to extract the rightmost characters of a string.

Specifically, when the ParmA is negative, the start position is calculated using the following formula:

 EXAMPLE....:  Fdate /Fsubstr  /A-2 /Qabcd
 CALCULATION:  StartColumn = length(ParmQ) + 1 + ParmA
               StartColumn =      4        + 1 + (-2)     = 3
          Fdate /Fsubstr /A7 /B2 /Q"STEVE FERG"   ===> "FE"
           Fdate /Fsubstr /A7     /Q"STEVE FERG"   ===> "FERG"
           Fdate /Fsubstr     /B5 /Q"STEVE FERG"   ===> "STEVE"

.EXAMPLES....: using a negative start position
          Fdate /Fsubstr /a-6 /B3 /Q"1994 Jun 03"   ===> "Jun

          rem extract the rightmost 6 characters of a string
          Fdate /Fsubstr /a-6     /Q"1994 Jun 03"   ===> "Jun 03"

          rem pad YEAR environment variable to the left with zeroes,
          rem to make sure it is 4 bytes long
          Fdate /Fsubstr /A-4 /q0000%year% /vyear

REMEMBER that Fdate eliminates redundant spaces when obtaining its parameter input:

           Fdate /Fsubstr /A7     /Q"STEVE FERG"      ===> "FERG"
           Fdate /Fsubstr /A7     /Q"STEVE  FERG"     ===> "FERG"
           Fdate /Fsubstr /A7     /Q"STEVE    FERG"   ===> "FERG"