# How to remove trailing characters?

**URL:** <https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-Code-Samples\
**Created:** [July 1, 2019, 6:53pm UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420 "2019-07-01T18:53:11Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Martin\_Breiner](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/martin_breiner/32/1293_2.png) [@Martin\_Breiner](https://techcommunity.softwareag.com/u/Martin_Breiner)\
**Post date:** [July 1, 2019, 6:53pm UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/1 "2019-07-01T18:53:11Z")

</div>

I want to remove all trailing “\_” from a alphanumeric field defined as A30.

Containing for example “_HELLOWORL\_D_\_\_”. The rest of the field will be filled by Natural with trailing blanks of course.  
Expected result should be “\_HELLOWORL\_D” with trailing blanks.

But how to accomplish that?

With EXAMINE I can search backward and could delete the characters, but how to tell EXAMINE that as soon any other character as “_" has been found it should stop?  
EXAMINE DIRECTION BACKWARD #FIELD-NAME FOR "_” DELETE

With EXAMINE I can also use the pattern method, but how to tell Natural that the “_" in the pattern is the to be searched character, as "_” indicates a single position that is not to be examined?  
EXAMINE #FIELD-NAME FOR PATTERN “\*\_” DELETE

Anybody got ideas on that.  
Thanks!

---

<div class="post-metadata">

**Author:** ![Jerome\_LeBlanc](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/jerome_leblanc/32/111_2.png) [@Jerome\_LeBlanc](https://techcommunity.softwareag.com/u/Jerome_LeBlanc)\
**Post date:** [July 1, 2019, 7:06pm UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/2 "2019-07-01T19:06:55Z")

</div>

There may be a more elegant approach, but you could always use brute force:

```auto

DEFINE DATA LOCAL                        
1 FIELD (A30) INIT <'H_LLO_WOR_D _____'> 
1 REDEFINE FIELD                         
  2 FIELD-A (A1/30)                      
1 #IX (I4)                               
END-DEFINE                               
*                                        
WRITE '=' FIELD                          
FOR.                                     
FOR #IX = 30 TO 1 STEP -1                
  DECIDE ON FIRST VALUE OF FIELD-A(#IX)  
    VALUE '_' RESET FIELD-A(#IX)       
    VALUE ' ' IGNORE                   
    NONE VALUE ESCAPE BOTTOM (FOR.)     
  END-DECIDE                             
END-FOR                                  
WRITE '=' FIELD                          
END                                      
```

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [July 1, 2019, 11:01pm UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/3 "2019-07-01T23:01:19Z")

</div>

I will presume that Jerome’s logic is acceptable to Martin. That is,"_HELLOWORL\_D_ \_\_" (note the embedded space in the trailing underscores) is correctly translated into "\_HELLOWORL\_D".

The solution is simple once you have a list of "good" characters - all values excluding space and underscore. Then, examine backwards for the first good character in the string, and reset all bytes following that position.

```auto
DEFINE DATA LOCAL
1 #TEXT (A10) INIT <'_del_x_ _'>
1 #P (I4)
1 #GOOD (A256) INIT <H'000102030405060708090A0B0C0D0E0F'
                       - H'101112131415161718191A1B1C1D1E1F'
                       - H'202122232425262728292A2B2C2D2E2F'
                       - H'303132333435363738393A3B3C3D3E3F'
                       - H'404142434445464748494A4B4C4D4E4F'
                       - H'505152535455565758595A5B5C5D5E5F'
                       - H'606162636465666768696A6B6C6D6E6F'
                       - H'707172737475767778797A7B7C7D7E7F'
                       - H'808182838485868788898A8B8C8D8E8F'
                       - H'909192939495969798999A9B9C9D9E9F'
                       - H'A0A1A2A3A4A5A6A7A8A9AAABACADAEAF'
                       - H'B0B1B2B3B4B5B6B7B8B9BABBBCBDBEBF'
                       - H'C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF'
                       - H'D0D1D2D3D4D5D6D7D8D9DADBDCDDDEDF'
                       - H'E0E1E2E3E4E5E6E7E8E9EAEBECEDEEEF'
                       - H'F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF'
                        >
                   1 REDEFINE #GOOD
  2 #G (B1/0:255)
END-DEFINE
EXAMINE #GOOD FOR ' ' DELETE /* SPACE is not a good character
EXAMINE #GOOD FOR '_' DELETE /* Underscore is not a good charaacter
*
EXAMINE DIRECTION BACKWARD
        #TEXT FOR #G (0:253) /* Exclude blanks at the end of #GOOD
        GIVING POSITION #P
ADD 1 TO #P
MOVE ' ' TO SUBSTRING (#TEXT, #P)
WRITE 'after:' #TEXT
END
```

If “_HELLOWORL\_D_” (with a trailing underscore due to the embedded space) is the correct solution, remove line 24 to make SPACE a good character.

---

<div class="post-metadata">

**Author:** ![Jerome\_LeBlanc](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/jerome_leblanc/32/111_2.png) [@Jerome\_LeBlanc](https://techcommunity.softwareag.com/u/Jerome_LeBlanc)\
**Post date:** [July 1, 2019, 11:35pm UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/4 "2019-07-01T23:35:25Z")

</div>

I knew Ralph would have a slick way to do it. Now if Steve Robinson will chime in on performance!

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [July 7, 2019, 11:14pm UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/5 "2019-07-07T23:14:33Z")

</div>

Been a bit hectic here; we just moved 30 miles north to escape urban blight, so response a bit late.

If Martin’s post is a complete description of the problem, I think the most efficient solution would be akin to Jerome’s solution.

Something like:

FOR.  
FOR #IX = 30 TO 1 STEP -1  
if FIELD-A(#IX) eq ‘\_’  
RESET FIELD-A(#IX)  
else  
ESCAPE BOTTOM (FOR.)  
END-FOR  
WRITE ‘=’ FIELD

In other words, if it is an underscore, change it to a blank. As soon as you see an non underscore, stop.

---

<div class="post-metadata">

**Author:** ![Helmut\_Spichtinger](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@Helmut\_Spichtinger](https://techcommunity.softwareag.com/u/Helmut_Spichtinger)\
**Post date:** [July 8, 2019, 3:07pm UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/6 "2019-07-08T15:07:22Z")

</div>

Another solution. The expression IF #FIELD = MASK (\*‘\_’/) examines, whether the last character in the character string is an underscore.

0010 DEFINE DATA LOCAL  
0020 1 #FIELD (A30) INIT \<‘_H\_LLO\_WOR\_D_ _X \_\_\_ \_\_‘\>  
0030 END-DEFINE  
0040 \*  
0050 WRITE ‘before:’ #FIELD  
0060 REP.  
0070 REPEAT  
0080 IF #FIELD = MASK (\*’_’/)  
0090 EXAMINE DIRECTION BACKWARD #FIELD FOR ‘\_’ DELETE FIRST  
0100 ELSE  
0110 ESCAPE BOTTOM (REP.)  
0120 END-IF  
0130 END-REPEAT  
0140 WRITE ‘after :’ #FIELD  
0150 END

Output:  
before: _H\_LLO\_WOR\_D_ \_X \_\_\_ \_\_  
after : _H\_LLO\_WOR\_D_ \_X

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [July 8, 2019, 9:39pm UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/7 "2019-07-08T21:39:53Z")

</div>

When very few underscores are present, my version is not the fastest (although pretty close), but with a reasonable number of trailing underscores, my CPU usage is half that of the other techniques. Here are the results (in CPU seconds) with 100k iterations.

```auto
Page 1 07/08/19 12:19:31
 
Text: 12345678901234567890123456789012345678901234567890
 Ralph: 000.07
 Steve: 000.04
Helmut: 000.07
 
Text: 1234567890123456789012345678901234567890123456789_
 Ralph: 000.12
 Steve: 000.10
Helmut: 000.15
 
Text: 1234567890123456789012345 _________________________
 Ralph: 000.73
 Steve: 001.35
Helmut: 002.33
 
Text: 1 _________________________________________________
 Ralph: 001.29
 Steve: 002.61
Helmut: 004.17
 
Text: __________________________________________________
 Ralph: 001.34
 Steve: 002.68
Helmut: 004.21
```

As you can see in the code, I reduced the table of valid characters to those found on a US keyboard. Your mileage may vary.

```auto
DEFINE DATA LOCAL
1 #MT (I4) CONST <5>
1 #TL (I4) CONST <50>
1 #TEXT (A50/#MT) INIT <'12345678901234567890123456789012345678901234567890'
                        ,'1234567890123456789012345678901234567890123456789_'
                        ,'1234567890123456789012345 _________________________'
                        ,'1 _________________________________________________'
                        ,' __________________________________________________'
                        >
                   (HD='Text')
                   1 REDEFINE #TEXT
  2 #OCC (#MT)
    3 #T (A1/#TL)
1 #MG (I4) CONST <93>
1 #GOOD (A93) /* excludes '_'
                   INIT <'abcdefghijklmnopqrstuvqxyz'
                        -&quot;ABCDEFGHIJKLMNOPQRSTUVQXYZ&quot;
                        -'0123456789'
                        -'`~!@#$%^&*()-=+[{]}\|''&quot;;:,<.>/?'
                        >
                   1 REDEFINE #GOOD
  2 #G (B1/#MG)
1 #CPU (I4)
1 #L (I4) CONST <100000>
1 #FOR (I4)
1 #C (I4)
1 #I (I4)
1 #J (I4)
1 #K (I4)
1 #P (I4)
END-DEFINE
FORMAT PS=30
ASSIGN #CPU = *CPU-TIME
FOR #I = 1 #L
  RESET INITIAL #TEXT (*)
END-FOR
ASSIGN #FOR = *CPU-TIME - #CPU
*
FOR #I = 1 #MT
  WRITE '=' #TEXT (#I)
  /*
  /* Ralph
  ASSIGN #CPU = *CPU-TIME
  FOR #J = 1 #L
    RESET INITIAL #TEXT (*)
    EXAMINE DIRECTION BACKWARD
            #TEXT (#I) FOR #G (*)
            GIVING POSITION #P
    IF #P <> #TL
      THEN
        ADD 1 TO #P
        MOVE ' ' TO SUBSTRING (#TEXT (#I), #P)
    END-IF
  END-FOR
  ASSIGN #C = *CPU-TIME - #CPU - #FOR
  WRITE ' Ralph:' #C (EM=999'.'99)
  /*
  /* Steve
  ASSIGN #CPU = *CPU-TIME
  FOR #J = 1 #L
    RESET INITIAL #TEXT (*)
    F. 
    FOR #K = #TL 1 -1
      IF #T (#I, #K) = '_'
          RESET #T (#I, #K)
        ELSE 
          ESCAPE BOTTOM (F.) 
      END-IF
    END-FOR
  END-FOR
  ASSIGN #C = *CPU-TIME - #CPU - #FOR
  WRITE ' Steve:' #C (EM=999'.'99)
  /*
  /* Helmut
  ASSIGN #CPU = *CPU-TIME
  FOR #J = 1 #L
    RESET INITIAL #TEXT (*)
    R. 
    REPEAT 
      IF #TEXT (#I) = MASK (*'_'/)
          EXAMINE DIRECTION BACKWARD #TEXT (#I) FOR '_' DELETE FIRST 
        ELSE 
          ESCAPE BOTTOM (R.) 
      END-IF 
    END-REPEAT
  END-FOR
  ASSIGN #C = *CPU-TIME - #CPU - #FOR
  WRITE 'Helmut:' #C (EM=999'.'99)
  SKIP 1
END-FOR
END
```

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [July 9, 2019, 3:23am UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/8 "2019-07-09T03:23:19Z")

</div>

The performance comparison shown above is hardly valid. Somehow, “my code” (which has no two dimensional arrays), has two uses of a two dimensional array (lines 64 and 65), while Ralph’s code has one use of a two dimensional array. Not surprising that when the data causes many executions of 64 & 65 Ralph’s code performs more efficiently.  
Also, the original posting is for an A30 field, not an A50 field.  
When I get a chance (see earlier posting about being in the middle of a Move), I will rewrite the performance comparison and post results here.

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [July 9, 2019, 9:02am UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/9 "2019-07-09T09:02:58Z")

</div>

Ralph & Helmut examine a string while Steve redefines the string as an array to interrogate individual bytes.

I added an array of strings to compare different counts of underscores, This might skew the results a bit, but even without the additional array, RalphCPU \< SteveCPU \< HelmutCPU when there are more than a handful of underscores.

---

<div class="post-metadata">

**Author:** ![Martin\_Breiner](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/martin_breiner/32/1293_2.png) [@Martin\_Breiner](https://techcommunity.softwareag.com/u/Martin_Breiner)\
**Post date:** [July 9, 2019, 10:22am UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/10 "2019-07-09T10:22:34Z")

</div>

Thanks for all the good replies. I was inspired by the solution of Jerome and will be using this.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/techcommunity/original/3X/c/d/cd19967bb605d28a72d77eb83a1cae22f3df2eb8.svg) [@system](https://techcommunity.softwareag.com/u/system)\
**Post date:** [July 9, 2019, 11:55am UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/11 "2019-07-09T11:55:08Z")

</div>

Variation of Ralph’s solution (include only "good" characters in scan table, no DELETE required)

```auto
    DEFINE DATA LOCAL  
    1 #TEXT (A10) INIT <'_del_x_ _'>  
    1 #P (I4)  
    1 #GOOD (A62) INIT <'abcdefghijklmnopqrstuvwxyz' 
                                           - 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
                                           - '01234567890'
                                         >
    1 REDEFINE #GOOD  
      2 #G (B1/1:62)  
    END-DEFINE  
    *  
    EXAMINE DIRECTION BACKWARD  
            #TEXT FOR #G (*)
            ABSOLUTE
            GIVING POSITION #P  
    ADD 1 TO #P  
    MOVE ' ' TO SUBSTRING (#TEXT, #P)  
    WRITE 'after:' #TEXT  
    END  
```

---

<div class="post-metadata">

**Author:** ![George\_Cooper](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/george_cooper/32/7831_2.png) [@George\_Cooper](https://techcommunity.softwareag.com/u/George_Cooper)\
**Post date:** [July 10, 2019, 1:33am UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/12 "2019-07-10T01:33:20Z")

</div>

I’m glad Martin found a solution to his liking. I doubt it is the most efficient, but it is straight forward coding, easy to understand, and gets the job done.

I think what this type of problem cries out for is an EXAMINE FOR LEADING, or EXAMINE FOR … DELETE/REPLACE LEADING, like the COBOL EXAMINE statement has always had. I’ve always missed having the “LEADING” option, which could also function as a “TRAILING” option when combined with EXAMINE BACKWARD. The NATURAL developers added the “FIRST” option a while back, but it’s not quite the same. As Helmut’s excellent example illustrates, use of DELETE FIRST for this problem requires use of an extra MASK (\*‘_"/) test to determine if the '_’ is actually a trailing character before using an EXAMINE to delete it. (Cool - I had forgotten the / in the MASK checks for a trailing pattern.) Also, a loop is required to delete or replace multiple '\_'s. An EXAMINE with a “LEADING” option could do it all with just one statement. (Hint, hint, Wolfgang 😉

I’ve been trying to test the efficiency of the first 2 versions, Jerome’s & Ralph’s, and my version similar to Helmut’s on my home PC with NaturalONE CE. Using the original (A30) “_HELLOWORL\_D_\_\_” test string, 10,000 iterations, my & Helmut’s version came in first, CPU=.03 sec, Ralph’s 2nd, .06 sec, and Jerome’s (& Steve’s?) 3rd at .17 sec. I need to change Ralph’s version to the smaller #GOOD array, since the NatONE Profiler showed most of the CPU time spent on the EXAMINE statement running through the #GOOD(A256) array. I expected Ralph’s to be fastest of all, but I’m not sure why his test results for Helmet’s version are so slow. More testing to come, just for grins, bump my loop count up to 100,000 for better resolution, and maybe follow Ralph’s logic to subtract out the FOR loop CPU time.

I can understand Steve’s objection to the 2nd subscript added to the character array method, probably causing extra CPU costs. Maybe Ralph’s code could be changed to rename the #TEXT (A50/5) to #TEXT-ARY (A50/5), add a 1 dimension #TEXT (A50), redefined by #T(A1/50) . Instead of RESET INITIAL #TEXT (\*) at the top of each loop, just move the next occurrence, #TEXT-ARY (#J) to #TEXT.

Hope Steve’s move goes well, and he can recuperate somewhat before getting back to this. I’m curious why he prefers indexing through a redefined character array for this situation. I thought he almost always in the past had showed the EXAMINE working on a string to be the most efficient, CPU-wise.

Cheers to all,  
George

---

<div class="post-metadata">

**Author:** ![Steve\_Robinson](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/steve_robinson/32/107_2.png) [@Steve\_Robinson](https://techcommunity.softwareag.com/u/Steve_Robinson)\
**Post date:** [July 10, 2019, 11:54am UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/13 "2019-07-10T11:54:39Z")

</div>

Hi George;

Yes, I have always advocated EXAMINE strings over other approaches, when doing things like ascertaining the number of occurrences in a long (usually more than 10 characters) string. Exceptions, which always seem to rear their head, are when you can exit a FOR loop after just a few iterations. Based on the original post, I thought that was what Martin was dealing with.

---

<div class="post-metadata">

**Author:** ![Helmut\_Spichtinger](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@Helmut\_Spichtinger](https://techcommunity.softwareag.com/u/Helmut_Spichtinger)\
**Post date:** [July 10, 2019, 4:09pm UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/14 "2019-07-10T16:09:49Z")

</div>

If Martin’s post is a complete description of the problem, I have two other solutions:

Solution #1:

```auto

DEFINE DATA LOCAL                                                
1 #FIELD (A30) INIT <'_HELLOWORL_D_ '>  
1 #POS (I4)                                            
1 #LENGTH (I4)                                            
END-DEFINE                                                       
*                                                                
WRITE 'before:' #FIELD                                           
IF #FIELD = MASK (*'_'/)                                         
  EXAMINE #FIELD FOR '_' WITH DELIMITERS                         
    GIVING POSITION IN #POS                                      
    GIVING LENGTH IN #LENGTH                                   
* WRITE '=' #POS '=' #LENGTH                                     
  IF #POS > 1                                                    
    #LENGTH := #POS - 1                                          
  END-IF                                                         
  COMPRESS ' ' TO SUBSTRING(#FIELD,#LENGTH)                      
END-IF                                                           
WRITE 'after :' #FIELD                                           
END                                                              
```

Solution #2:

```auto

DEFINE DATA LOCAL                                                    
1 #FIELD (A30) INIT <'_HELLOWORL_D _________'>      
END-DEFINE                                                           
*                                                                    
WRITE 'before:' #FIELD                                               
IF #FIELD = MASK (*'_'/)                                             
  EXAMINE DIRECTION BACKWARD #FIELD FOR '_' WITH DELIMITERS '_'      
    REPLACE ' '                                                      
/* one underscore will always remain at the end of the string        
  EXAMINE DIRECTION BACKWARD #FIELD FOR '_' REPLACE FIRST WITH ' '   
END-IF                                                               
WRITE 'after :' #FIELD                                               
END                                                                  
```

---

<div class="post-metadata">

**Author:** ![Jerome\_LeBlanc](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/jerome_leblanc/32/111_2.png) [@Jerome\_LeBlanc](https://techcommunity.softwareag.com/u/Jerome_LeBlanc)\
**Post date:** [July 10, 2019, 4:51pm UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/15 "2019-07-10T16:51:04Z")

</div>

Can you stand one more solution? I can do it in two lines of code. No promises about efficiency.

```auto

DEFINE DATA LOCAL                                   
1 #FIELD (A30) INIT <'H_LLO_WOR_D _____'>            
1 #ARRAY (A30/30)                                   
END-DEFINE                                          
*                                                   
WRITE '#FIELD:' #FIELD                              
*
SEPARATE FIELD INTO #ARRAY (*) WITH DELIMITER '_'   
COMPRESS #ARRAY (*) INTO FIELD-2 WITH DELIMITER '_' 
*
WRITE '#FIELD:' #FIELD
*                            
END                                                 
```

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [July 10, 2019, 7:41pm UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/16 "2019-07-10T19:41:46Z")

</div>

Nice, but I can’t imagine Martin not having an example with multiple embedded underscores.

For example, O\_\_W starts with 2 underscores which are reduced to 1.

```auto
#FIELD: H_LLO __WOR_D_____
#FIELD: H_LLO_WOR_D
```

And I would expect this not to perform too well.

---

<div class="post-metadata">

**Author:** ![Helmut\_Spichtinger](https://avatars.discourse-cdn.com/v4/letter/h/e0b2c6/32.png) [@Helmut\_Spichtinger](https://techcommunity.softwareag.com/u/Helmut_Spichtinger)\
**Post date:** [July 11, 2019, 9:44am UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/17 "2019-07-11T09:44:58Z")

</div>

> [@Jerome LeBlanc](#):
>
> Can you stand one more solution? I can do it in two lines of code.

```
:-)

```

---

<div class="post-metadata">

**Author:** ![sagi\_achituv1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/sagi_achituv1/32/386_2.png) [@sagi\_achituv1](https://techcommunity.softwareag.com/u/sagi_achituv1)\
**Post date:** [August 26, 2019, 12:22pm UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/18 "2019-08-26T12:22:26Z")

</div>

I would just point you to the TRIM , that enables to supress leading or trailing blanks -  
so in combination with Exanime statment to replace the ‘\_’ char to blank - you may have a simple solution.

The TRIM function is relativly new, so you may missed it.

Sagi

---

<div class="post-metadata">

**Author:** ![Ralph\_Zbrog](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/ralph_zbrog/32/78_2.png) [@Ralph\_Zbrog](https://techcommunity.softwareag.com/u/Ralph_Zbrog)\
**Post date:** [August 28, 2019, 5:52pm UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/19 "2019-08-28T17:52:29Z")

</div>

More likely that no one mentioned \*TRIM because it applies only to DYNAMIC variables, which were not involved in this thread.

---

<div class="post-metadata">

**Author:** ![sagi\_achituv1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/sagi_achituv1/32/386_2.png) [@sagi\_achituv1](https://techcommunity.softwareag.com/u/sagi_achituv1)\
**Post date:** [August 29, 2019, 10:45am UTC](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420/20 "2019-08-29T10:45:22Z")

</div>

\*TRIM is not limited to only DYNAMIC variables, as it can be used for static varibales, as well.  
see [url][https://techcommunity.softwareag.com/ecosystem/documentation/natural/nat911mf/func/func\_trim.htm?hi=trim+trimmed](https://techcommunity.softwareag.com/ecosystem/documentation/natural/nat911mf/func/func_trim.htm?hi=trim+trimmed)

[Next page](https://techcommunity.softwareag.com/t/how-to-remove-trailing-characters/204420.md?page=2)
