[CLOSED] Keep certain characters in string and removing all special/other characters
Hi,
I was wondering if anyone has other methods of keeping certain characters in a alphanumeric field and dumping all other characters. I came up with a function, which is used when a TABLE FILE is issued. I also don't know what all the special characters could be. The performance is decent since I'm applying it only to a limited number of records but still looking for alternatives.
DEFINE FUNCTION F_REMOVE_SPECIALCHAR (IN_STRING/A300)
TMP_STRING/A300=IN_STRING;
-SET &SMSF_FRSC_I = 0;
-REPEAT CHK_ALL_CHAR 240 TIMES
-SET &SMSF_FRSC_I = &SMSF_FRSC_I + 1;
-* Ascii codes of all the characters to keep:
-* space(32), #(35), -(45), 0-9, a-z, A-Z
-IF ( (&SMSF_FRSC_I EQ 32) OR (&SMSF_FRSC_I EQ 35) OR (&SMSF_FRSC_I EQ 45) OR ((&SMSF_FRSC_I GE 48) AND (&SMSF_FRSC_I LE 57)) OR ((&SMSF_FRSC_I GE 65) AND (&SMSF_FRSC_I LE 90)) OR ((&SMSF_FRSC_I GE 97) AND (&SMSF_FRSC_I LE 122)) ) THEN GOTO SMSF_FRSC_END_CHK_ALL_CHAR;
-* Convert unwanted characters to space
TMP_STRING/A300 = CTRAN(300, TMP_STRING, &SMSF_FRSC_I, 32, 'A300');
-SMSF_FRSC_END_CHK_ALL_CHAR
-* Removing extra spaces
STRING_RM_SPACE/A300=SQUEEZ(300,TMP_STRING,'A300');
F_REMOVE_SPECIALCHAR/A310 = STRING_RM_SPACE;
END
-RUN
Looking forward to suggestions ... thanks! JLThis message has been edited. Last edited by: JL,
Year(s) of experience in WebFOCUS: 5+. Using WebFOCUS 7.7.03 on Windows platform with Oracle/SQL Server.
May 21, 2013, 02:51 PM
<HarryL>
Starting with WebFOCUS 7.1.0, string replacements (more than 1 character) can be done using the STRREP function. The following illustrates an example on how to convert CRLF characters to spaces: