toPSLExpression Method

Class: ByteString

Description

This method converts the value of the byte string into a PSL/M expression that represents the value, and can be inserted in M code.

 

If the byte string represents a canonic numeric value, then the value is returned unchanged. Otherwise, the byte string does not contain control characters or invalid sequences, the method returns ({String}ByteStringObject).addQuotes().

 

Otherwise, the method returns a single $CHAR()-function or $ZCHAR()-function that lists all the byte values.

 

The current implementation of the function assumes that the $CHAR() or $ZCHAR() code generated to represent the value does not exceed a length limit.

Syntax

ByteStringObject.toPSLExpression()

Parameters

none

Returns

A PSLExpression that will only contain characters that is valid in M / PSL source code.

When Became Available

Profile V7.0

Example

type String STR1 = "Knäckebröd"

type String STR2 = "123.456"

type String STR3 = "Knäcke"_9.char()_bröd"

 

type String BS1 = STR1.toByteString()

type String BS2 = STR2.toByteString()

type String BS3 = STR3.toByteString()

 

// The value returned for BS1 and for BS2 will be independent of

// Runtime.charsetName

type PSLExpression PE1 = BS1.toPSLExpression() // 123.456

type PSLExpression PE2 = BS2.toPSLExpression() // "Knäckebröd" (quoted)

 

// The text that you see when you write BS3 depends on Runtime.charsetName

// for "M": $C(75,110,228,99,107,101,9,98,114,246,100)

// for "UTF-8": $ZC(75,110,195,164,99,107,101,9,98,114,195,182,100)

type PSLExpression PE3 = BS3.toPSLExpression()

write PE3