# Remove extra character

**URL:** <https://techcommunity.softwareag.com/t/remove-extra-character/79924>\
**Category:** Forum\
**Tags:** Adabas-Natural, Natural, Natural-on-Mainframes\
**Created:** [January 14, 2009, 4:23pm UTC](https://techcommunity.softwareag.com/t/remove-extra-character/79924 "2009-01-14T16:23:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ekangal](https://avatars.discourse-cdn.com/v4/letter/e/edb3f5/32.png) [@Ekangal](https://techcommunity.softwareag.com/u/Ekangal)\
**Post date:** [January 14, 2009, 4:23pm UTC](https://techcommunity.softwareag.com/t/remove-extra-character/79924/1 "2009-01-14T16:23:04Z")

</div>

Hi,

Does anybody know a quick way of writing a natural program to remove the extra character from keyword.For eg,

```auto
DEFINE DATA LOCAL
1 A (A30)
1 TEMP-A (A30)
1 HARFLER(A1/1:5) CONST<'A','B','C','D','E'>
1 I (I4)
1 L (I4)
END-DEFINE
A:='DxAT1YC&?.K'
WRITE '=' A
EXAMINE A FOR ' ' GIVING LENGTH L
FOR I=1 TO L
  IF HARFLER(*)=SUBSTRING(A,I,1)
    COMPRESS TEMP-A SUBSTRING(A,I,1) INTO TEMP-A LEAVING NO
  END-IF
END-FOR
A:=TEMP-A
WRITE '=' A
END
```

Thanks

---

<div class="post-metadata">

**Author:** ![Finn\_the\_Dane1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/finn_the_dane1/32/132_2.png) [@Finn\_the\_Dane1](https://techcommunity.softwareag.com/u/Finn_the_Dane1)\
**Post date:** [January 14, 2009, 5:19pm UTC](https://techcommunity.softwareag.com/t/remove-extra-character/79924/2 "2009-01-14T17:19:49Z")

</div>

Hi Ekangal,  
I know this is the opposite of your example, but if you make a negative-list instead of your positivelist you could use the EXAMINE syntax like below.  
Finn

DEFINE DATA LOCAL  
1 A (A30)  
1 HARFLER(A1/1:5) CONST\<‘A’,‘B’,‘C’,‘D’,‘E’\>  
END-DEFINE  
A:=‘DxAT1YC&?.K’  
WRITE ‘=’ A  
EXAMINE A FOR HARFLER(\*) DELETE  
WRITE ‘=’ A  
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:** [January 14, 2009, 7:55pm UTC](https://techcommunity.softwareag.com/t/remove-extra-character/79924/3 "2009-01-14T19:55:41Z")

</div>

Here is much simpler (and efficient ) code:

DEFINE DATA LOCAL  
1 A (A30)  
1 TEMP-A (A30)  
1 HARFLER(A1/1:5) CONST\<‘A’,‘B’,‘C’,‘D’,‘E’\>  
1 H-STRING (A5) CONST \<‘ABCDE’\>  
1 I (I4)  
1 L (I4)  
1 #PIECES (A30/1:60)  
END-DEFINE  
A:=‘DxAT1YC&?.K’  
WRITE ‘=’ A  
SEPARATE A INTO #PIECES (_) WITH RETAINED DELIMITERS H-STRING  
COMPRESS #PIECES (2) #PIECES (4) #PIECES (6) #PIECES (8)  
INTO A LEAVING NO SPACE  
\*\*EXAMINE A FOR ’ ’ GIVING LENGTH L  
\*\* FOR I=1 TO L  
\*\* IF HARFLER(_)=SUBSTRING(A,I,1)  
\*\* COMPRESS TEMP-A SUBSTRING(A,I,1) INTO TEMP-A LEAVING NO  
\*\* END-IF  
\*\*END-FOR  
\*\*A:=TEMP-A  
WRITE ‘=’ A  
END

You would actually need more occurrences of #PIECES in the COMPRESS. I took advantage of knowing how many targets existed in the string.

SEPARATE is a much more powerful statement than most programmers realize.

steve

---

<div class="post-metadata">

**Author:** ![Finn\_the\_Dane1](https://sea1.discourse-cdn.com/techcommunity/user_avatar/techcommunity.softwareag.com/finn_the_dane1/32/132_2.png) [@Finn\_the\_Dane1](https://techcommunity.softwareag.com/u/Finn_the_Dane1)\
**Post date:** [January 14, 2009, 8:33pm UTC](https://techcommunity.softwareag.com/t/remove-extra-character/79924/4 "2009-01-14T20:33:00Z")

</div>

A small enhancement proposal for Steve’s enlightning solution…

- hadn’t noticed that variant of seperate before !!  
By making the redefine the compress statement becomes a bit more simple !  
Finn

DEFINE DATA LOCAL  
1 A (A30)  
1 H-STRING (A5) CONST \<‘ABCDE’\>  
1 #PIECES (A30/1:60)  
1 REDEFINE #PIECES  
2 #PIECES2 (A30/1:30,1:2)  
END-DEFINE  
A:=‘DxAT1YC&?.K’  
WRITE ‘=’ A  
SEPARATE A INTO #PIECES (_) WITH RETAINED DELIMITERS H-STRING  
COMPRESS #PIECES2 (_,2)  
INTO A LEAVING NO SPACE  
WRITE ‘=’ A  
END

---

<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:** [April 2, 2021, 2:51pm UTC](https://techcommunity.softwareag.com/t/remove-extra-character/79924/5 "2021-04-02T14:51:21Z")

</div>


