Removing Blanks with COBOL

Hello

How to remove trailing spaces in a string with COBOL
for example 'abcd ' would become 'abcd'

Thank you.

7 answers

  1. Moderator
    Hi,

    UNSTRING ... DELIMITED BY ALL SPACES INTO ...

    That should work...

    See you, Blux
     "The idiots dare everything. It's even how we recognize them." 
    1
    1. Thank you, I tried
      but apparently it doesn't work!
      There are still whitespaces
      that I want to only eliminate the whitespaces on the right
      for example:
      'DE SEVRES '
      do not delete the space between 'de' and 'sevres'
      See you later
      0
      1. Moderator
        Ok, so in this case, the only solution is to redefine your input area as a table:

        05 toto occurs 200.
        10 str pic x.

        move tavariable to toto.

        And then you make a loop that decrements i from 200 to 1 and you test x(i) until x(i) is different from space. As soon as your condition is true, you copy the rest into another variable (with 'string').

        --
        See you Blux
         "The fools, they dare to do anything. It's even how you recognize them"
        0
        1. Hello
          If at first, you don't know where to put the spaces, it seems difficult!
          'DE SEVRES " How can you know that you need to leave a space between DE and
          SEVRES???
          Once this issue is determined, the rest is solved...
          KAIDI
          0
          1. Moderator
            Euh well yes, he said 'remove the whites on the right'... ;-)

            --
            See you Blux
             "Stupid people, they dare everything. That's even how you recognize them"
            0
        2. do you need to remove all spaces or not?
          'DE SEVRES" should it become "DESEVRES"?
          0
          1. Moderator
            No, he only wants to remove the spaces on the right...

            --
            A+ Blux
             "Stupid people dare to do anything. It's precisely how we recognize them"
            0
        3. He can only do it if he knows in advance the words (or the lengths) from which he has to remove the spaces!!
          0
          1. Hello,

            thank you all for your very precious help!
            0
            1. hello

              I think we need to use an occurs and test the value character by character

              but do not perform the delete if val (I) = spaces and val (i + 1) not = spaces

              best regards
              0
            2. Moderator
              @claudius51It's been 3 years since the problem was solved...

              --

              See you, Blux
               "Fools dare everything. It's even how we recognize them"
              0