0
votes

I am new to this language. I used TRIM function to remove space characters but I am not sure how to remove it after each comma(,).

DEFINE VARIABLE cdata AS CHARACTER NO-UNDO INIT  " one, two, three, four ".

DISPLAY trim(cdata) FORMAT "x(70)".

The display value is "one, two, three, four". Why I cannot remove the space characters after each comma(,)?

does any one have thoughts?

2

2 Answers

3
votes

TRIM removes white space characters at the beginning and the end of the character variable, not in the middle.

In this case here, you can use

DISPLAY REPLACE (cdata, " ", "") FORMAT "x(70)".
2
votes

When using a function for the first time, maybe try reading the help page on the function first?

https://documentation.progress.com/output/ua/OpenEdge_latest/index.html#page/dvref/trim-function.html

TRIM function

Removes leading and trailing white space, or other specified characters, from a CHARACTER or LONGCHAR expression. The data type of the returned value matches the data type of the expression passed to the function.

Your requirement is a bit vague and Mike's answer is removing all spaces from the string. If you only want the spaces after the commas removed:

def var cdata as char initial  " one, two, three, four ".
def var ic as int.

do ic = 1 to num-entries( cdata ):
   entry( ic, cdata ) = trim( entry( ic, cdata ) ).
end.

message cdata.

https://abldojo.services.progress.com:443/#/?shareId=5f1c3abc4b1a0f40c34b8c75