5-60 Command Reference
MID
Purpose Extracts a sub-field from a string.
Syntax MID
buffer-field1
,
buffer-field2
,
start
,
length
[
,
[
invalid label
] [
, valid label
] ]
Process The MID command extracts a sub-field from
buffer-field1
and copies it into
buffer-
field2
; starting with the
start
position and extracting
length
number of characters.
Buffer-field1
,
buffer-field2
,
start
, and
length
can be one the following:
Buffer-field1, 2, Start
and
Length
Description
INPUT Input Buffer
Logical Field Name
(TEMP1)
Temporary Buffer
Field
Logical Field Name (LU1) Lookup Buffer Field
Logical Field Name (PR1) Printer Buffer Field
Logical Field Name
(Field1) [Index]
Array Buffer Field
Buffer-field1
only:
String
ASCII string delimited
by double quotes
Buffer-field1, start,
and
length
only:
Number
Number prefixed by a
number sign (#)
Rules:
Length
and
Start
must be numeric.
Optional Fields
Invalid
and
valid labels
are discussed in "Script Flow" at the beginning of this
chapter. The exception is as follows:
If
buffer-field2
overflows,
start
is greater than
length
, or
invalid label
is defined,
control passes to that label.
Example 1
This example extracts a five-character substring starting at position 5 of LOCATION
and copies it into TEMP1.
MID LOCATION,TEMP1,#5,#5
Example 2
This example extracts a substring of LengthNum characters starting at position
StartNum of LOCATION and copies it into TEMP1.
MID LOCATION,TEMP1,StartNum,LengthNum
See Also
LEFT
LSTRIP
RIGHT
RSTRIP