I’m just learning COBOL; I’m writing a program that simply echos back user input. I have defined a variable as:
User-Input PIC X(30).
Later when I ACCEPT User-Input, then DISPLAY User-Input ” plus some extra text”, it has a bunch of spaces to fill the 30 characters. Is there a standard way (like Ruby’s str.strip!) to remove the extra spaces?
One would hope for a more elegant way of simply trimming text strings
but this is pretty much the standard solution… The trimming part
is done in the SHOW-TEXT paragraph.
Produces the following output:
Note that the PERFORM VARYING statement relies on the left to
right evaluation of the UNTIL clause to avoid out-of-bounds
subscripting on USER-INPUT in the case where it contains only
blank spaces.