Compaq AAQ2G1FTK Marine Radio User Manual


 
Using the STRING, UNSTRING, and INSPECT Statements
5.2 Separating Data Using the UNSTRING Statement
When a sending string is delimited by the end of the sending item rather than by
a match on a delimiter, the delimiter string is of zero length and the DELIMITER
item is space-filled. The phrase should be used only where needed. In this
example, the character that delimits the last sending string is not needed, so no
DELIMITER phrase follows FIELD2C.
The data item named in the DELIMITER phrase must be described as an
alphanumeric item. It can contain editing characters, and it can also be a group
item.
When you use both DELIMITER and COUNT phrases, the DELIMITER phrase
must precede the COUNT phrase. Both of the data items named in these phrases
can be subscripted or indexed. If they are subscripted, the subscript can be varied
as a side effect of the UNSTRING operation.
5.2.5 Controlling UNSTRING Scanning Using the POINTER Phrase
Although the UNSTRING statement scan usually starts at the leftmost position
of the sending item, the POINTER phrase lets you control the character position
where the scan starts. Scanning, however, remains left to right.
When a sending item is to be unstrung into multiple receiving items, the choice
of delimiters and the size of subsequent receiving items depends on the size
of the first sending string and the character that delimited that string. Thus,
the program needs to move the first sending item, hold its scanning position in
the sending item, and examine the results of the operation to determine how to
handle the sending items that follow.
This is done by using an UNSTRING statement with a POINTER phrase that
fills only the first receiving item. When the first string has been moved to a
receiving item, the compiler begins the next scanning operation one character
beyond the delimiter that caused the interruption. The program examines the
new position, the receiving item, the delimiter value, and the sending string size.
It resumes the scanning operation by executing another UNSTRING statement
with the same sending item and pointer data item. In this way, the UNSTRING
statement moves one sending string at a time, with the form of each succeeding
move depending on the context of the preceding string of data.
The POINTER phrase must follow the last receiving item in the UNSTRING
statement. You are responsible for initializing the pointer before the UNSTRING
statement executes. Consider the following two UNSTRING statements with
their accompanying POINTER phrases and tests:
MOVE 1 TO PNTR.
UNSTRING FIELD1 DELIMITED BY ":"
OR TAB
OR CR
OR ALL SPACE
INTO FIELD2A DELIMITER IN DELIMA COUNT IN LSIZEA
WITH POINTER PNTR.
IF LSIZEA = 0 GO TO NO-LABEL-PROCESS.
IF DELIMA = ":"
IF PNTR > 8 GO TO BIG-LABEL-PROCESS
ELSE GO TO LABEL-PROCESS.
IF DELIMA = TAB GO TO BAD-LABEL PROCESS.
.
.
.
UNSTRING FIELD1 DELIMITED BY ... WITH POINTER PNTR.
5–14 Using the STRING, UNSTRING, and INSPECT Statements