Removing all special characters from a string in a 4GL process

How to remove all special characters from a string in Progress 4GL?

+2
source share
1 answer

I think it depends on your definition of special characters.

You can delete ANY character with REPLACE. Just set the replaceable part of the string to empty ("").

Syntax:

REPLACE (source string, from-string, to-string)

Example:

DEFINE VARIABLE cOldString AS CHARACTER   NO-UNDO.
DEFINE VARIABLE cNewString AS CHARACTER   NO-UNDO.

cOldString = "ABC123AACCC".

cNewString = REPLACE(cOldString, "A", "").

DISPLAY cNewString FORMAT "x(10)".

You can use REPLACE to remove the complete match string. For instance:

REPLACE("This is a text with HTML entity &", "&", "").

" " . "ASCII", linefeed, bell .., REPLACE CHR.

( , ):

CHR ()

: , , . (ASCII ).

, Ö: s (ASCII 214) , :

REPLACE("ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ", "Ö", "").

REPLACE("ABCDEFGHIJKLMNOPQRSTUVWXYZÅÄÖ", CHR(214), "").

, . :

FUNCTION cleanString RETURNS CHARACTER (INPUT pcString AS CHARACTER):
    DEFINE VARIABLE iUnwanted AS INTEGER     NO-UNDO EXTENT 3.
    DEFINE VARIABLE i         AS INTEGER     NO-UNDO.
    /* Remove all capital Swedish letters ÅÄÖ */
    iUnwanted[1] = 197.
    iUnwanted[2] = 196.
    iUnwanted[3] = 214.

    DO i = 1 TO EXTENT(iUnwanted):

        IF iUnwanted[i] <> 0 THEN DO:
            pcString = REPLACE(pcString, CHR(iUnwanted[i]), "").
        END.
    END.

    RETURN pcString.
END.

DEFINE VARIABLE cString AS CHARACTER   NO-UNDO INIT "AANÅÅÖÖBBCVCÄÄ".

DISPLAY cleanString(cString) FORMAT "x(10)".

, :

  • SUBSTRING: . .
  • ASC: CHR, - ASCII ).
  • INDEX: .
  • R-INDEX: INDEX, .
  • STRING: .
+6

Source: https://habr.com/ru/post/1672843/


All Articles