Previous Topic Next topic Print topic


INSPECT Statement (Tallying, Replacing, and Converting)

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"
Initial Value of ITEM COUNT-0 COUNT-1 COUNT-2 COUNT-3 COUNT-4 Final Value of ITEM
EFABDBCGABEFGG 3 1 1 0 5 TUXYXVWRXYZZPZ
BABABC 2 0 0 1 1 SXYXYZ
BBBC 0 1 0 2 0 SSVW

Example 2:

     inspect item tallying
         count-0 for characters
         count-1 for all "A";

     inspect item replacing
         characters by "Z"
         all "A" by "X"
Intial Value of ITEM COUNT-0 COUNT-1 Final Value of ITEM
BBB 3 0 ZZZ
ABA 3 0 ZZZ

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"
Initial Value of ITEM COUNT-0 COUNT-1 COUNT-2 Final Value of ITEM
BBEABDABABBCABEE 3 0 2 BBEXYZXYXYZCABVE
ADDDDC 0 0 4 AZZZZC
ADDDDA 0 0 5 AZZZZZ
CDDDDC 0 0 0 CDDDDC
BDBBBDB 0 3 0 BDWWWDB

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 "#".
Initial Value of ITEM Final Value of ITEM
AC"AEBDFBCD#AB"D AC"XEYXFYZX#AB"D
Previous Topic Next topic Print topic