Focal Point
[CLOSED] Keep certain characters in string and removing all special/other characters

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/9657078036

May 17, 2013, 10:38 AM
JL
[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!
JL

This 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:

IDX/A2000 = ID;
CRLF/A2 = HEXBYT(13,'A1') | HEXBYT(10,'A1');
DD/A2 = ' ';
IDESCA/A2000 = STRREP(2000,IDX,2,CRLF,2,DD,2000,'A2000');
May 22, 2013, 07:14 AM
dhagen
Build a FUSE routine. See the stored procedure reference manual for doc.


"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott