typestar

STRING ... DELIMITED in COBOL

STRING splices fields into one tag, trimming each by its delimiter.

IDENTIFICATION DIVISION.
PROGRAM-ID. STRING-DELIMITED.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 PORT-NAME    PIC X(10) VALUE "Valparaiso".
01 BERTH-NO     PIC X(2)  VALUE "9".
01 MOORING-TAG  PIC X(30).
PROCEDURE DIVISION.
*> STRING splices fields; DELIMITED BY trims or keeps them whole.
    STRING PORT-NAME DELIMITED BY SPACE
           " berth "  DELIMITED BY SIZE
           BERTH-NO   DELIMITED BY SPACE
        INTO MOORING-TAG
    END-STRING
    DISPLAY "Tag: [" MOORING-TAG "]"
    STOP RUN.

How it works

  1. DELIMITED BY SPACE stops copying a field at its first blank.
  2. DELIMITED BY SIZE keeps the literal " berth " whole, spaces included.
  3. INTO MOORING-TAG receives the splice, and END-STRING closes the verb.

Keywords and builtins used here

The run, in numbers

Lines
16
Characters to type
456
Tokens
56
Three-star pace
35 tpm

At the three-star pace of 35 tokens a minute, this run takes about 96 seconds.

Type this snippet

Step 2 of 3 in Tables & strings, step 20 of 27 in Language basics.

← Previous Next →