char Method

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:

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()