-3

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.

D_Animus
  • 43
  • 9
  • You might want to ask your actual question. Which apparently is something like "can I use regular expressions with Progress". – Tom Bascom Sep 08 '17 at 13:18

2 Answers2

2

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.

TheDrooper
  • 1,182
  • 1
  • 7
  • 14
  • thank you but is there any way to replace it by using Regular expressions. – D_Animus Sep 08 '17 at 05:51
  • 1
    Regular expressions aren't natively supported in OpenEdge, but you may be able to use a .Net object: https://community.progress.com/community_groups/openedge_development/f/19/t/29622 – TheDrooper Sep 08 '17 at 13:46
2

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.
Tom Bascom
  • 13,405
  • 2
  • 27
  • 33
  • Thank you Tom, but i want to reduce iteration. if there is any way to do the same task by using regular expression please help me. – D_Animus Sep 08 '17 at 05:52
  • If you imagine that a regular expression doesn't iterate over the string you're going to be disappointed – Tom Bascom Sep 08 '17 at 21:36