在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.
以上兩種方法都可以達到去掉字符串末尾的空格的效果,根據實際需求選擇適合的方法即可。