The INSPECT statement can be used to tally the number of occurrences of specific character strings, to replace characters by other characters, or to convert from one set of characters to another. Setting the conditons for these inspections can be quite complex. The following examples demonstrate some of the variations and uses of this verb.
In each of the following examples of the INSPECT statement, COUNT-n is assumed to be zero immediately prior to execution of the statement. The results shown for each example, except the last, are the result of executing the two successive INSPECT statements shown above them.
Example 1:
inspect item tallying count-0 for all "AB", all "D" count-1 for all "BC" count-2 for leading "EF" count-3 for leading "B" count-4 for characters; inspect item replacing all "AB" by "XY", "D" by "X" all "BC" by "VW" leading "EF" by "TU" leading "B" by "S" first "G" by "R" first "G" by "P" characters by "Z"
Example 2:
inspect item tallying count-0 for characters count-1 for all "A"; inspect item replacing characters by "Z" all "A" by "X"
Example 3:
inspect item tallying count-0 for all "AB" before "BC" count-1 for leading "B" after "D" count-2 for characters after "A" before "C" inspect item replacing all "AB" by "XY" before "BC" leading "B" by "W" after "D" first "E" by "V" after "D" characters by "Z" after "A" before "C"
Example 4:
inspect item tallying count-0 for all "AB" after "BA" before "BC"; inspect item replacing all "AB" by "XY" after "BA" before "BC"
Initial Value of Item | COUNT-0 | Final Value of Item |
---|---|---|
ABABABABC | 1 | ABABXYABC |
Example 5:
inspect item converting "ABCD" to "XYZX" after quote before "#".
The above INSPECT is equivalent to the following INSPECT:
inspect item replacing all "A" by "X" after quote before "#" all "B" by "Y" after quote before "#" all "C" by "Z" after quote before "#" all "D" by "X" after quote before "#".