How to get rid of trailing and embedded spaces in a string?

I am writing a program that converts national and international account numbers to IBAN numbers. First I need to form a line: bank identifier + branch identifier + account number + ISO country code without the trailing spaces that may be present in these fields. But not every account number has the same length, some account numbers have industry identifiers, while others do not, so I will always have trailing spaces from these fields.

My working storage looks something like this:

      01 Input-IBAN.
          05 BANK-ID                    PIC N(10) VALUE "LOYD".
          05 BRANCH-ID                  PIC N(10) VALUE "     ".
          05 ACCOUNT-NR                 PIC N(28) VALUE "012345678912   ". 
          05 COUNTRY-CODE               PIC N(02) VALUE "GB".
      01 Output-IBAN                    PIC N(34).

I have provided some values ​​for an example; in reality, this will depend on the input. The branch code is optional, so I leave it blank in the example.

Basically I want to go from this input: "LOYD 012345678912 GB"

to that: "LOYD012345678912GB"

- , , ? FUNCTION REVERSE, INSPECT . , . - ? , , , ?

EDIT: , .

+4
2

, . , , . "" , .

, , , , - "IBAN". , https://en.wikipedia.org/wiki/International_Bank_Account_Number#Structure, :

IBAN . , ,

, , , , . , ( ), . (), .

STRING .

, , .


, , , , .

       MOVE SPACE                   TO OUTPUT-IBAN
       STRING                       BANK-ID 
                                    BRANCH-ID 
                                    ACCOUNT-NR 
                                    COUNTRY-CODE 
         DELIMITED                  BY SPACE 
         INTO                       OUTPUT-IBAN 

STRING , , OUTPUT-IBAN STRING.

, SPACE . , .

STRING , . Gilbert LeBlanc , STRING . , , - ( SPACES, ), , , , " ". , .

STRING 34 , . , STRING ON OVERFLOW, , . ON OVERFLOW, NOT ON OVERFLOW, END-STRING. / STRING, ON/NOT ON .

/ .

COBOL "". , . IBAN , .


:

-, "" , , ( COBOL), Gilbert's.

, , , , .

COBOL . , COBOL . AcuCOBOL ( Micro Focus), INSPECT TRAILING, . GnuCOBOL TRAILING INSPECT , , FUNCTION, TRIM, , ( ) STRING.

       move space                   to your-output-field
       string function 
               trim 
                ( your-first-national-source 
                  trailing )
              function 
               trim 
                ( your-second-national-source 
                  trailing )
              function 
               trim 
                ( your-third-national-source 
                  trailing )
              ...
         delimited                  by size
         into                       your-output-field

, , PIC N, , - .

COBOL 85...

FUNCTION REVERSE, INSPECT. INSPECT , , . , , .

(PIC N). , , , , . , PIC N, - , LENGTH OF, , FUNCTION LENGTH .

- UTF-16. , "ASCII", . , z/OS, EBCDIC, - .

       MOVE ZERO                    TO a-count-for-each-field 
       INSPECT FUNCTION 
                REVERSE 
                 ( each-source-field )
         TALLYING                   a-count-for-each-field 
          FOR LEADING               SPACE 

-.

?

-, . -, .

:

MOVE SPACE                   TO output-field
STRING field-1 ( 1 : length-1 )
       field-2 ( 1 : length-2 )
  DELIMITED BY               SIZE
  INTO                       output-field

, /.

MOVE , , fooobar.com/questions/1633762/..., .

? , , , .

, , . COBOL, , , , , , , "". . .

Enterprise COBOL V5.2 (, V5.1 , ), , , , .

, , . National , FUNCTION LENGTH ( ), LENGTH OF ( ). . .

+7

COBOL. , .

77 SUB1  PIC S9(4) COMP. 
77 SUB2  PIC S9(4) COMP. 

MOVE 1 TO SUB2 
PERFORM VARYING SUB1 FROM 1 BY 1 
        UNTIL SUB1 > LENGTH OF INPUT-IBAN
    IF INPUT-IBAN(SUB1:1) IS NOT EQUAL TO SPACE
        MOVE INPUT-IBAN(SUB1:1) TO OUTPUT-IBAN(SUB2:1)
        ADD +1 TO SUB2
    END-IF
END-PERFORM.
+1

All Articles