Compaq AAQ2G1FTK Marine Radio User Manual


 
Using the STRING, UNSTRING, and INSPECT Statements
5.3 Examining and Replacing Characters Using the INSPECT Statement
Figure 54 Typical REPLACING Phrase
ZK6053GE
INSPECT FIELD1 REPLACING
Replacing argument
"0"ALL BY "$"
Each argument in an argument list used with either a TALLYING or
REPLACING operation can have a delimiter item (BEFORE/AFTER phrase)
associated with it. If the delimiter item is not present, the argument is applied to
the entire item. If the delimiter item is present, the argument is applied only to
that portion of the item specified by the BEFORE/AFTER phrase.
5.3.4.1 Setting the Scanner
The INSPECT operation begins by setting the scanner to the leftmost character
position of the item being inspected. It remains on this character until an
argument has been matched with a character (or characters) or until all
arguments have failed to find a match at that position.
5.3.4.2 Active/Inactive Arguments
When an argument has a BEFORE/AFTER phrase associated with it, that
argument has a delimiter and may not be eligible to participate in a comparison
at every position of the scanner. Thus, each argument in the argument list has
an active/inactive status at any given setting of the scanner.
For example, an argument that has an AFTER phrase associated with it starts
the INSPECT operation in an inactive state. The delimiter of the AFTER phrase
must find a match before the argument can participate in the comparison.
When the delimiter finds a match, the compiler generates code that retains the
character position beyond the matched character string; then, when the scanner
reaches or passes this position, the argument becomes active. This is shown in
the following example:
INSPECT FIELD1 TALLYING TLY
FOR ALL "B" AFTER "X".
If FIELD1 has a value of ABABXZBA, the argument B remains inactive until the
scanner finds a match for delimiter X. Thus, argument B remains inactive while
the compiler generates code that scans character positions 1 to 5. At character
position 5, delimiter X finds a match, and because the character position beyond
the matched delimiter character is the point at which the argument becomes
active, argument B is compared for the first time at character position 6. It finds
a successful match at character position 7, causing TLY to be incremented by 1.
Table 5–11 shows an INSPECT...TALLYING statement that is scanning FIELD1,
tallying in TLY, and looking for the arguments and delimiters listed in the left
column. Assume that TLY is initialized to 0.
522 Using the STRING, UNSTRING, and INSPECT Statements