Kbase P22506: How to extract a part of a string, up to a maximum length, w
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  4/3/2003 |
|
Status: Unverified
GOAL:
How to extract a part of a string, up to a maximum length, without truncating the end-word?
FIX:
/*------------------------------------------------------------------------------
Purpose: Extract a line of a string without truncating the end word.
Parameters:
INPUT iLineLength : The Maximum length of the line to be extracted.
INPUT cInputString: The string from which we want to extract the line.
INPUT lLCFReplace : TRUE if line feeds, carriage returns and form feeds are to be replaced by blanks.
OUTPUT cOutputLine: The extracted line returned to the calling procedure.
------------------------------------------------------------------------------*/
DEFINE INPUT PARAMETER iLineLength AS INTEGER NO-UNDO.
DEFINE INPUT PARAMETER cInputString AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER lLCFReplace AS LOGICAL NO-UNDO.
DEFINE OUTPUT PARAMETER cOutputLine AS CHARACTER NO-UNDO.
DEFINE VARIABLE cCharacter AS CHARACTER NO-UNDO.
DEFINE VARIABLE iLastSpacePos AS INTEGER NO-UNDO.
IF lLCFReplace THEN DO:
ASSIGN
cInputString = REPLACE ( cInputString , CHR(10) , CHR(32) )
cInputString = REPLACE ( cInputString , CHR(11) , CHR(32) )
cInputString = REPLACE ( cInputString , CHR(12) , CHR(32) )
cInputString = REPLACE ( cInputString , CHR(13) , CHR(32) )
cInputString = REPLACE ( cInputString , CHR(14) , CHR(32) )
cInputString = REPLACE ( cInputString , CHR(15) , CHR(32) ).
END.
cOutputLine = SUBSTRING (cInputString, 1,iLineLength, "CHARACTER").
cCharacter = SUBSTRING (cInputString, 1,iLineLength + 1, "CHARACTER").
IF INDEX ( CHR(10) + CHR(11) + CHR(12) + CHR(13), cCharacter) = 0 THEN
ASSIGN
iLastSpacePos = R-INDEX(cOutputLine, CHR(32))
cOutputLine = SUBSTRING (cOutputLine, 1,iLastSpacePos, "CHARACTER").
END PROCEDURE.