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
DELIMITED BY SPACEstops copying a field at its first blank.DELIMITED BY SIZEkeeps the literal" berth "whole, spaces included.INTO MOORING-TAGreceives the splice, andEND-STRINGcloses the verb.
Keywords and builtins used here
DATADISPLAYDIVISIONIDENTIFICATIONPROCEDURESECTIONSTOPSTRING
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.
Step 2 of 3 in Tables & strings, step 20 of 27 in Language basics.