SQUEEZE


NCHAR

 

The SQUEEZE instruction moves the logical contents of a string variable, numeric variable, constant, or literal to another string variable while removing characters. The instruction uses the following format:

 

(1)

[label]

SQUEEZE

{source},{dest}[,{delete}]

(2)

[label]

SQUEEZE

{source},{dest}[,KEEP={chars}]

 

Where:

label

Optional. A Program Execution Label.

source

Required. A previously defined Character String Variable, National Character String Variable, Numeric Variable, Constant, or Literal whose Logical String is used.

dest

Required. A previously defined Character String Variable or National Character String Variable that receives the {source} value.

delete

Optional. A previously defined Character String Variable, National Character String Variable, Literal, or National Character String Literal indicating the characters to delete from the source string during the transfer.

chars

Optional. A previously defined Character String Variable, National Character String Variable, Literal or National Character String Literal indicating the characters to keep from the source string during the transfer.

Flags Affected: EOS

Note the following:

  1. When {source} is a character variable, the transfer 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 unless {source} and {dest} are the same.

  2. The transfer into {dest} begins at the first physical character. If any characters are transferred, the Form Pointer of {dest} is set to one (1) and the Length Pointer of {dest} is set to the last character moved. If no characters are transferred, the Form Pointer and Length Pointer of {dest} is set to zero (0).

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

  4. If {delete} is not specified or is a null variable, spaces are removed.

  5. If {chars} is specified, it indicates characters to keep from the source string during the transfer. The KEEP option was added in version 9.0.

  6. If {chars} is a Null String, spaces are the only characters kept when the {source} string data is transferred to the {dest} variable.

 

Example 1:

 

  

SQUEEZE

DATA,OUTPUT

 

 

Variable

PL

FP

LP

Contents

Before:

DATA

20

1

20

1 2 3 4 5 6 7 8 9 0

 

OUTPUT

20

1

5

87654

 

After:

DATA

20

1

20

1 2 3 4 5 6 7 8 9 0

 

OUTPUT

20

1

10

1234567890

 

No Condition Flags are set (all FALSE).

 

Example 2:

 

  

SQUEEZE

DATA,OUTPUT,"X"

 

 

Variable

PL

FP

LP

Contents

Before:

DATA

20

1

20

1X2 3 4 5 6 7 8 9 0X

 

OUTPUT

20

1

5

87654

 

After:

DATA

20

1

20

1X2 3 4 5 6 7 8 9 0X

 

OUTPUT

20

1

18

12 3 4 5 6 7 8 9 0

 

No Condition Flags are set (all FALSE).

 

Example 3:

 

  

SQUEEZE

DATA,OUTPUT,"XYZ"

 

 

Variable

PL

FP

LP

Contents

Before:

DATA

20

1

20

1X2X3Y4Y5Y6Z7Z8Z9Z0Z

 

OUTPUT

7

1

5

87654

 

After:

DATA

20

1

20

1X2X3Y4Y5Y6Z7Z8Z9Z0Z

 

OUTPUT

7

1

7

1234567

 

The EOS Condition Flag is set since OUTPUT was too small to contain all the possible characters.

 

Example 4:

 

  

SQUEEZE

DATA,DATA,"7"

 

 

Variable

PL

FP

LP

Contents

Before:

DATA

10

1

10

1234567890

 

After:

DATA

10

1

9

123456890

 

No Condition Flags are set (all FALSE).

 

Example 5:

 

  

SQUEEZE

DATA,DATA,KEEP="73"

 

 

Variable

PL

FP

LP

Contents

Before:

DATA

20

1

20

1 2 3 4 5 6 7 8 9 0

 

After:

DATA

20

1

2

37

 

No Condition Flags are set (all FALSE).

 

See Also: Character String Instructions

 



PL/B Language Reference SPLICE STORE