Consultor Eletrônico



Kbase 18939: How To Use Replace() With Editor Widget For Carriage Returns
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   30/09/2010
Status: Verified

GOAL:

4GL/ABL: How to use the REPLACE function strip out unwanted carriage return CR, line feed LF and form feed FF characters from a text field or variable?

GOAL:

How to replace LINEFEED (LF) CHR(10), FORMFEED (FF) CHR(12) and RETURN / ENTER (CR) CHR(13) characters with the SPACE CHR(32) character in a text field or variable?

FACT(s) (Environment):

All Supported Operating Systems
Progress 9.x
OpenEdge 10.x

FIX:

The following code snippet copies the value of the Customer.Comments field into the cOutputLine variable and proceeds to replace all the occurrences of LINEFEED (LF) CHR(10), FORMFEED (FF) CHR(12) and RETURN / ENTER (CR) CHR(13) characters in the variable with the SPACE CHR(32) character before outputting the resulting value to the myfile.txt file:
DEFINE VARIABLE cOutputLine AS CHARACTER NO-UNDO.
OUTPUT TO "myfile.txt".
FOR EACH Customer NO-LOCK:
cOutputLine = Customer.Comments.
/* Replace all the LINEFEED LF characters with the SPACE charactrer */
cOutputLine = REPLACE(cOutputLine, CHR(10), CHR(32)).
/* Replace all the FORMFEED FF characters with the SPACE charactrer */
cOutputLine = REPLACE(cOutputLine, CHR(12), CHR(32)).
/* Replace all the ENTER / RETURN CR characters with the SPACE charactrer */
cOutputLine = REPLACE(cOutputLine, CHR(13), CHR(32)).
/* Output the resulting string on a the current line and start a new line */
PUT UNFORMATTED cOutputLine SKIP.
END.
OUTPUT CLOSE.