CHOP


NCHAR

 

The CHOP instruction moves one string to another, deleting all trailing spaces in the process. The instruction uses the following format:

 

 

[label]

CHOP

{source}[{sep}{dest}][:

 

 

 

LEADING={leading}][:

 

 

 

TRAILING={trailing}]

 

Where:

label

Optional. A Program Execution Label.

source

Required. A previously defined Character String Variable or National Character String Variable containing the string that is moved.

sep

Required. A comma or one of the following prepositions: BY, TO, OF, FROM, USING, WITH, IN, or INTO.

dest

Optional. A previously defined Character String Variable or National Character String Variable that receives the source string.

leading
A decimal number, Numeric Variable, Numeric literal, or Expression where a non-zero value allows leading spaces to be deleted. A zero value does not allow leading spaces to be deleted. If this keyword value is not specified, the default behavior is to not delete leading spaces. (10.6A)
trailing
A decimal number, Numeric Variable, Numeric literal, or Expression where a non-zero value allows trailing spaces to be deleted. A zero value does not allow trailing spaces to be deleted. If this keyword value is not specified, the default behavior is to allow trailing spaces to be deleted. (10.6A)

Flags Affected: EOS

Note the following:

  1. The transfer from the {source} operand begins at the Form Pointed character and continues through the Length Pointed character (i.e., the Logical String) or until {dest} is full (whichever occurs first). The {source} operand remains unchanged when two operands are specified.

  2. The transfer into {dest} begins at the first physical character. The Form Pointer of {dest} is set to one (1) and the Length Pointer to the last character moved.

  3. If the {dest} is too small for the transfer, the EOS Condition Flag is set.

  4. Trailing spaces in the {source} string are not moved.

  5. If {source} is null or all blanks, the Form Pointer of {dest} is set to zero (CLEARed).

  6. If {dest} is not specified, the {source} variable is modified.

  7. Enhanced ARRAY processing is supported. If an array is specified (without an index), the CHOP instruction is performed on each element within the array.

  8. Examples when CHOP instruction uses LEADING and/or TRAILING keywords.

  9.  

    $ON

    FORM

    "1"

    $OF

    FORM

    "0"

    dIn

    DIM

    50

    dOut

    DIM

    50

    .

     

     

    .Delete leading spaces only

    .

     

     

     

    MOVE

    " ABCD ", dIn

     

    CHOP

    dIn, dOut, LEADING=$ON,TRAILING=$OFF

    .

     

     

    .Delete both leading and trailing spaces.

    .The CHOP deletes trailing spaces by default.

    .

     

     

     

    MOVE

    " NEXT ", dIn

     

    CHOP

    dIn, dOut, LEADING=1

    .

     

     

    .Delete leading and trailing spaces with operand

    .

     

     

     

    MOVE

    " FIRST ", dIn

     

    CHOP

    dIn, TRAILING=1, LEADING=1

 

 

 

See Also: Example Code, Character String Instructions

 



PL/B Language Reference BUMP CLEAR