-----Original message-----
From: Dan Rasch drasch27@xxxxxxxxxxx
Date: Tue, 02 Mar 2010 16:44:01 -0600
To: midrange-l@xxxxxxxxxxxx
Subject: embedded blanks in COBOL string
I have to 'scrunch' out blanks for a string in a COBOL program, and
used some INSPECT / TALLYING followed by substring logic, but I
kept thinking there must be and easier way to remove embedded
spaces from a string. Using COBOL.
Comments?
Been a long time since I used COBOL, on any platform.
This may not be >easier<.
My memory of specific COBOL syntax is decidedly rusty.
Set up an array with enough entries to hold all the words in a given line. Each entry needs to be as large as the longest word.
Set start position to search to 1.
set array word pointer to 1.
Start a loop.
Unstring the original string into a position of the table, identified by a subscript. Have the unstring stop after the first delimiter has been reached. The unstring would use the start position variable, which also becomes the position where the delimiter was found. When unstring stops, save that position and use for the next iteration.
Increment the word pointer.
Copy delimiter location to start position.
Repeat the loop until end of line.
Then, string the words back together.
OR, simpler:
Input line and output line, same size. Two pointers.
Set both pointers to 1.
Start loop
if source character pointer greater than 1 and source character not blank and previous source character was blank, increment destination pointer BEFORE storing source character. Increment both pointers.
If source character is blank increment source pointer.
Increment the source table pointer.
Continue until source pointer reaches end of line.
Maybe that will get you started.
John McKee
As an Amazon Associate we earn from qualifying purchases.