.STRING_FUNCS: SUBSTR (Substring) Function
.ALIAS.......: SUBSUBFU
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:
- StartColumn = length(ParmQ) + 1 + ParmA
EXAMPLE....: Fdate /Fsubstr /A-2 /Qabcd
CALCULATION: StartColumn = length(ParmQ) + 1 + ParmA
StartColumn = 4 + 1 + (-2) = 3
- If /Q is omitted, Fdate reports an error.
- If /A is zero, Fdate reports an error.
- If /A is omitted, it defaults to 1 (that is, the start of the string).
- If /A is negative, and longer than the length of the string, then the
start column is 1 (the start of the string)
- If /B (length) is so great that it exceed the length of the /Q input
string, then only the remainder of the string is returned.
- If /B is zero, Fdate returns a null string.
- If /B is omitted, it defaults to 999.
.EXAMPLES:
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"