Consultor Eletrônico



Kbase P116459: How to remove the NULL characters appended at the end of a MEMPTR variable? 
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   15/09/2009
Status: Verified

GOAL:

How to remove the NULL characters appended at the end of a MEMPTR variable?

GOAL:

How to clean the NULL characters from a MEMPTR variable?

FACT(s) (Environment):

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

FIX:

When a string is assigned to a MEMPTR whose size is greater than the LENGTH of the string, Progress appends NULL characters for the remaining bytes of the MEMPTR. The following code shows one way to clean out these NULL characters:
DEFINE VARIABLE cCleanString AS LONGCHAR NO-UNDO.
DEFINE VARIABLE iInitialMemptrSize AS INTEGER NO-UNDO.
DEFINE VARIABLE iAcsiiNumber AS INTEGER NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
ASSIGN
iInitialMemptrSize = 1024.
/* Set the initial memory pointer variable size to a large value */
SET-SIZE(mMemoryPointer) = iInitialMemptrSize.
/* Put a short string into the memory pointer location causing NULLs */
PUT-STRING ( mMemoryPointer , 1, iInitialMemptrSize) = "Short String".
/* Pump the non NULL data into the LONGCHAR */
DO iCounter = 1 TO iInitialMemptrSize:
iAcsiiNumber = GET-BYTE(mMemoryPointer, iCounter).
IF iAcsiiNumber = 0 THEN LEAVE.
cCleanString = cCleanString + CHR(iAcsiiNumber).
END.
/* Free the memory allocated to the memory pointer */
SET-SIZE(mMemoryPointer) = 0.
/* Allocate the correct size of memory pointer */
SET-SIZE(mMemoryPointer) = LENGTH(cCleanString) + 1.
/* Pump the data without the NULLs back into the memory pointer */
PUT-STRING ( mMemoryPointer , 1) = cCleanString.