Using the STRING, UNSTRING, and INSPECT Statements
5.3 Examining and Replacing Characters Using the INSPECT Statement
These statements count the number of words in the English statement in
FIELD1, assuming that no more than three spaces separate the words in the
sentence, that the sentence ends with a period, and that the period immediately
follows the last word. When FIELD1 has been scanned, T2 contains the number
of spaces between the words. Because a count of the spaces renders a number
that is one less than the number of words, the conditional statement adds 1 to
the count.
The first argument removes any leading spaces, counting them in a different tally
counter. This shortens FIELD1 by preventing the application of the second to the
fourth arguments until the scanner finds a nonspace character. The BEFORE
phrase on each of the other arguments causes them to become inactive when
the scanner reaches the period at the end of the sentence. Thus, the BEFORE
phrases shorten FIELD1 by making the second to the fourth arguments inactive
before the scanner reaches the rightmost position of FIELD1. If the sentence in
FIELD1 is indented with tab characters instead of spaces, a second LEADING
argument can count the tab characters. For example:
INSPECT FIELD1 TALLYING
T1 FOR LEADING SPACES
T1 FOR LEADING TAB
T2 FOR ALL "
"
.
.
.
When an argument list contains a CHARACTERS argument, it should be the
last argument in the list. Because the CHARACTERS argument always matches
the item, it prevents the application of any arguments that follow in the list.
However, as the last argument in an argument list, it can count the remaining
characters in the item being inspected. Consider the following example.
MOVE 0 TO T1 T2 T3 T4 T5.
INSPECT FIELD1 TALLYING
T1 FOR LEADING SPACES
T2 FOR ALL "." BEFORE ","
T3 FOR ALL "+" BEFORE ","
T4 FOR ALL "-" BEFORE ","
T5 FOR CHARACTERS BEFORE ",".
If FIELD1 is known to contain a number in the form frequently used to input
data, it can contain a plus or minus sign, and a decimal point; furthermore,
the number can be preceded by spaces and terminated by a comma. When this
statement is compiled and executed, it delivers the following results:
•
T1 contains the number of leading spaces.
•
T2 contains the number of periods.
•
T3 contains the number of plus signs.
•
T4 contains the number of minus signs.
•
T5 contains the number of remaining characters (assumed to be numeric).
The sum of T1 to T5, plus 1, gives the character position occupied by the
terminating comma.
Using the STRING, UNSTRING, and INSPECT Statements 5–29
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......