Class: Number
Description
This method instantiates a String consisting of a single character. The value returned by the method depends on the value of the Number instance:
If the method is applied to a Number instance with a value less than zero, then the empty string is returned.
If the method is applied to a Number instance with a value greater than or equal to zero and less than 256, then that character is returned under all circumstances. Note that the representation of the character depends on the value of Runtime.charsetName.
If Runtime.charsetName = "M", and the value is greater than or equal to 256, then the empty string will be returned.
If Runtime.charsetName = "UTF-8", and the value represents a valid code point in the Unicode character set, then that character is returned.
If Runtime.charsetName = "UTF-8", and the value does not represents a valid code point in the Unicode character set, and VIEW "BADCHAR" is not in effect, then the empty string will be returned.
If Runtime.charsetName = "UTF-8", and the value does not represents a valid code point in the Unicode character set, and VIEW "BADCHAR" is in effect, then a %GTM-E-BADCHAR runtime exception will be thrown.
Syntax
NumberObject.char()
Parameters
none
Returns
A String consisting of a single character
Throws
Throws error %GTM-E-BADCHAR if the method is applied to a Number instance with a positive value that does not map to a valid character in Runtime.charsetName, and VIEW "BADCHAR" is in effect for the current process.
When Became Available
Profile V7.0
Example
// These examples always work on all platforms, although the internal
// representation may be different depending on Runtime.charsetName
type Number NUM1 = 120
type String STR1 = NUM1.char() // "x"
type Number NUM2 = -120
type String STR2 = NUM2.char() // ""
type Number NUM3 = 246
type String STR1 = NUM3.char() // "ö"
// This one is also OK under all circumstances, although the implied
// value will depend on Runtime.charsetName
type String MXCHR = PSL.maxCharValue.char()
// Code point 526 is a valid Unicode character, but beyond the
// maximum for Ruuntime.charsetName="M"
type Number MUM4 = 526
type String STR4 = NUM4.char()
write STR4.length() // 0 (for "M") or 1 (for "UTF-8")
// Code point 55296 (U+D800) is a not valid Unicode character
// if Runtime.charsetName="M": returns ""
// if Runtime.charsetName="M" and VIEW "BADCHAR" off: returns ""
// if Runtime.charsetName="M" and VIEW "BADCHAR" on: throws %GTM-E-BADCHAR
type Number MUMERR = 55296
type String STRERR = NUMERR.char()