Consultor Eletrônico



Kbase 15560: 4GL. How to find and replace non-printable characters in your data
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/15/2008
Status: Verified

GOAL:

How to find and replace non-printable characters in your data

FACT(s) (Environment):

Progress 4GL

FIX:

Many times depending on how data is entered it can contain bad characters.  

Information such as carriage returns and tabs can appear as black blocks or can wreak havoc when printing.  The easiest way to rectify this error is by scanning your data while using the replace function.  The example below displays the issue and the end results of using this method.

Some common characters to look for are:
CHR(10)  is a line feed
CHR(12) is a form feed
CHR(13) is a carriage return

Before we can replace these bad characters though we need to know which ones they are.  This can be done like so;

1)  Find one of the fields with the bad data.
   FIND FIRST table WHERE field = "identifier".
2)  Display the field.
   DISPLAY field.
3)  Run this and count the characters in this field to the bad character.

4)  Use the following command to see what character that is.
   DISPLAY ASC(SUBSTRING(field,bad character number,1)).
5)  This number is the one that should be used in the REPLACE function as shown below.  For the example we used CHR(13).

NOTE: Caution should be used when implementing this method.  Sometimes these characters are contained in your data for formatting purposes.

A simple for each statement can be used to scan a field for these characters.  The example uses a static string for instructional purposes.  

Example:
---------------------------Replacer.p-------------------------------

DEFINE VARIABLE X AS CHARACTER FORMAT "X(60)".
ASSIGN X = " THIS IS A TEST " + CHR(13) + "IT CONTAINS A CARRIAGE-RETURN".
DISPLAY X WITH FRAME A.
ASSIGN X = REPLACE(X, CHR(13), " " ).
DISPLAY X WITH FRAME B.