× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.




-----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.

This thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.