Remove extra character

Hi,

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

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

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

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

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