CHR$ function

Purpose

Convert one or more ASCII codes, ranges, and/or strings into a single string containing the corresponding ASCII character(s).

Syntax

s$ = CHR$(expression [,expression] [,...])
s$
= CHR$(string_expression [,...])
s$
= CHR$(x& TO y& [,...])

Remarks

CHR$ returns a string, each character of which represents  the corresponding ASCII codes of the arguments.  Single or multiple arguments may be specified, each of which may be a numeric character code expression, string expression, or numeric character code range.  These argument types may be freely intermixed in a single CHR$ function.  Numeric ASCII arguments must be in the range -1 through 255.

CHR$(x& TO y&) returns a sequence of all characters from CHR$(x&) through CHR$(y&) inclusive, provided x& <= y&.  If x& > y&, an empty string is returned.  For example, CHR$(65 TO 70) returns "ABCDEF".

The expanded CHR$ definition is intended to assist in the encoding of multi-byte strings, to avoid the need for concatenation operations.  For example, the CHR$ function can be used to create COLLATE strings for the ARRAY SORT and ARRAY SCAN statements at run-time, and can be used to create string equates at compile time:

$colstring = CHR$(0 TO 131, 97, 133 TO 255)

The following lines are functionally equivalent, and return the same string result:

a$ = CHR$("Line1", 13, 10, "Line2")

a$ = "Line1" & CHR$(13) & CHR$(10) & "Line2"

a$ = "Line1" & $CRLF & "Line2"

CHR$ complements the ASC function, which returns the ASCII code of a nominated character in a string.  In addition, CHR$ with a parameter value of -1 returns an empty string for that parameter.  For example, CHR$(65, -1, 66) returns "AB".

CHR$ is also handy for creating characters that are difficult to enter at the keyboard, such as international characters for text output, or control code sequences for printer output, etc.

See also

ARRAY SCAN, ARRAY SORT, ASC functionASC statement, NUL$, SPACE$, STRING$

Example

H$ = CHR$("a$=", $DQ, 33, $DQ+$DQ, 35 TO 39, 40, $DQ)

Result

a$="!""#$%&'("