Progress 4gl control character remove

1.5k views Asked by At

I want to remove all control character from the given string. i don't want to use Replace method because it take multiple iteration. Help me.

Thanks in advance.

2

There are 2 answers

2
Tom Bascom On

Depending on what you define as a control character and what character set you are using this might do the trick. Or at least point you in a helpful direction:

define variable i as integer   no-undo.
define variable n as integer   no-undo.
define variable c as character no-undo.
define variable s as character no-undo.
define variable x as character no-undo.

s = "something with control characters in it".
x = "".

n = length( s ).
do i = 1 to n:
  c = substring( s, i, 1 ).
  if asc( c ) >= 32 and asc( c ) < 127 then
    x = x + c.
end.
2
TheDrooper On

You may not like it, but REPLACE is the simplest way to do it. I've used this code to strip non-printable characters from a string. This will replace the control characters with a space:

DEFINE VARIABLE str AS CHARACTER NO-UNDO.
DEFINE VARIABLE iLoop AS INTEGER NO-UNDO.

DO iLoop = 1 TO 31:
    str = REPLACE(str, CHR(iLoop), " ").
END.

Since there are multiple control characters that have to be removed, it seems that any solution will involve multiple iterations.