Skip to main content
Module 6 · Lesson 1 of 211/16 in the course~16 min
Module lessons (1/2)

STRING, UNSTRING and INSPECT

Lesson preview5 hands-on exercises readyCourse COBOL · Module 6 — Strings, INSPECT and Subroutines

Concatenate fields by eliminating trailing blanks with DELIMITED BY SPACE, parse CSV with UNSTRING and count/replace patterns with INSPECT.

What you'll learn in this lesson

  • Concatenate multiple fields by eliminating trailing spaces using STRING ... DELIMITED BY SPACE / SIZE ... INTO ... END-STRING.
  • Separate delimited records (such as CSV fields or "2026-11-15" dates) into individual variables using UNSTRING ... DELIMITED BY ... INTO ....
  • Count characters and normalize strings in-place using INSPECT ... TALLYING and INSPECT ... REPLACING.

Overview

In modern languages first + " " + last automatically manages the length of strings; in COBOL WS-FIRST PIC X(15) containing "MARIO" physically has 10 trailing spaces ("MARIO "). This is where STRING, UNSTRING and INSPECT come into play.

The DELIMITED BY clause establishes where to stop the copy of each source:

Sections covered in this lesson

  1. 11. Smart concatenation with STRING
  2. 22. Reverse parsing with UNSTRING
  3. 33. Scan and normalize with INSPECT
  4. 44. Tracking the cursor index with WITH POINTER
  5. 5Try it yourself
Pro Lesson · Module 6 — Strings, INSPECT and Subroutines

Unlock "STRING, UNSTRING and INSPECT" and the full Course COBOL curriculum

Concatenate fields by eliminating trailing blanks with DELIMITED BY SPACE, parse CSV with UNSTRING and count/replace patterns with INSPECT.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course COBOL plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.