在COBOL中去掉字符串末尾的空格可以通过以下几种方法实现:
01 MY-STRING PIC X(10) VALUE 'COBOL '.
01 RESULT-STRING PIC X(10).
MOVE SPACES TO RESULT-STRING.
STRING MY-STRING DELIMITED BY SPACE
INTO RESULT-STRING
ON OVERFLOW
END-STRING
END-STRING.
MOVE FUNCTION TRIM(RESULT-STRING) TO RESULT-STRING.
DISPLAY RESULT-STRING.
01 MY-STRING PIC X(10) VALUE 'COBOL '.
01 LENGTH PIC 9(2).
01 RESULT-STRING PIC X(10).
MOVE LENGTH OF MY-STRING TO LENGTH.
INSPECT FUNCTION REVERSE(MY-STRING)
TALLYING LENGTH FOR LEADING SPACES.
MOVE FUNCTION SUBSTRING(MY-STRING, 1, LENGTH) TO RESULT-STRING.
DISPLAY RESULT-STRING.
以上两种方法都可以达到去掉字符串末尾的空格的效果,根据实际需求选择适合的方法即可。