Kbase P75637: 4GL/ABL: How to clean the NULL characters from a file?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  4/27/2010 |
|
Status: Verified
GOAL:
4GL/ABL: How to clean the NULL characters from a file?
GOAL:
How to replace all the NULL characters in a file to the space character?
FACT(s) (Environment):
All Supported Operating Systems
Progress 9.x
OpenEdge 10.x
FIX:
The following code replaces all the occurrences of the NULL character CHR(0) with the space character CHR(32).
DEFINE VARIABLE mVariable AS MEMPTR NO-UNDO.
DEFINE VARIABLE cFileWithNulls AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFileWithoutNulls AS CHARACTER NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
/* Initialize file names and mempointer variable size */
ASSIGN
cFileWithNulls = "InputFileName"
cFileWithoutNulls = "OutputFileName"
FILE-INFO:FILE-NAME = cFileWithNulls
SET-SIZE(mVariable) = FILE-INFO:FILE-SIZE.
/* Import the file with nulls into the mempointer variable */
INPUT FROM VALUE(cFileWithNulls) BINARY NO-MAP NO-CONVERT.
IMPORT UNFORMATTED mVariable.
INPUT CLOSE.
/* Replace all null characters with a space CHR(32) */
DO iCounter = 1 TO FILE-INFO:FILE-SIZE:
IF GET-BYTE(mVariable, iCounter) = 0 THEN
PUT-BYTE(mVariable, iCounter) = 32.
END.
/* Export the cleaned data without nulls to the output file */
OUTPUT TO VALUE(cFileWithoutNulls) BINARY NO-MAP NO-CONVERT.
EXPORT mVariable.
OUTPUT CLOSE.