Compaq AAQ2G1FTK Marine Radio User Manual


 
Using the STRING, UNSTRING, and INSPECT Statements
5.3 Examining and Replacing Characters Using the INSPECT Statement
5.3.6 Using the REPLACING Phrase
When an INSPECT statement contains a REPLACING phrase, that statement
selectively replaces characters or groups of characters in the designated item.
The REPLACING phrase names a search argument of one or more characters and
a condition under which the string can be applied to the item being inspected.
Associated with the search argument is the replacement value, which must be
the same length as the search argument. Each time the search argument finds a
match in the item being inspected, under the condition stated, the replacement
value replaces the matched characters.
A BEFORE/AFTER phrase can be used to delimit the area of the item being
inspected. A search argument applies only to the delimited area of the item.
5.3.6.1 The Search Argument
The search argument of the REPLACING phrase names a character string and a
condition under which the character string should be compared to the delimited
string being inspected.
The CHARACTERS form of the search argument specifies that every character in
the delimited string being inspected should be considered to match an imaginary
character that serves as the search argument. Thus, the replacement value
replaces each character in the delimited string. For example:
INSPECT ITEMA REPLACING CHARACTERS ...
The ALL, LEADING, and FIRST forms of the search argument specify a
particular character string, which can be represented by a literal or an identifier.
The search argument character string can be any length. However, each
character of the argument must match a character in the delimited string before
the compiler considers the argument matched. For example:
INSPECT ITEMA REPLACING ALL ...
The necessary literal and identifier characteristics are as follows:
A literal character string must be either nonnumeric or a figurative constant
(other than ALL literal). A figurative constant, such as SPACE or ZERO,
represents a single character and can be written as ‘‘ ’’ or ‘‘0’’ with the
same effect. Because a figurative constant represents a single character,
the replacement value must be one character long.
An identifier must represent an elementary item of DISPLAY usage. It can be
any class. However, if it is not alphabetic, the compiler performs an implicit
redefinition of the item. This redefinition is identical to the BEFORE/AFTER
delimiter redefinition discussed in Section 5.3.2.
The words ALL, LEADING, and FIRST supply conditions that further delimit the
inspection operation:
ALL specifies that each match the search argument finds in the delimited
character string is replaced by the replacement value. When a literal
follows the word ALL, it does not have the same meaning as the figurative
constant, ALL literal. The figurative constant meaning of ALL ‘‘,’’ is a string
of consecutive commas, as many as the context of the statement requires.
ALL ‘‘,’’ as a search argument of the REPLACING phrase means ‘‘replace
each comma without regard to adjacent characters.’’
530 Using the STRING, UNSTRING, and INSPECT Statements