BASIC Language Reference Manual > Command and Function Reference >

CHR$ Function


Converts a Unicode or ASCII code number for a character (glyph) into a string representation of that character.


CHR$(numeric expression)

Remarks and Examples

Each character that can be displayed has a numeric code associated with it. Traditionally, in most BASIC dialects, the character set has been based on the ASCII standard, where the decimal numbers 32 through 126 are associated with printable characters.

ReadyBASIC uses the Unicode standard, which supports the characters of virtually all languages in common use today. Characters are associated with a number between 0 and 65535 in the Unicode charts. Numbers 32 through 126 remain the same as in ASCII.

The CHR$ function converts a number to a string containing the character represented by the number.

For example, the capital letter "A" is represented by the ASCII (and Unicode) code number 65.


The following sample program shows a range of characters:

10 FOR X% = 32 TO 42
20 PRINT "ASCII code: "; X%; "   Character: "; CHR$(X%)
30 NEXT X%
ASCII code: 32   Character:
ASCII code: 33   Character: !
ASCII code: 34   Character: "
ASCII code: 35   Character: #
ASCII code: 36   Character: $
ASCII code: 37   Character: %
ASCII code: 38   Character: &
ASCII code: 39   Character: '
ASCII code: 40   Character: (
ASCII code: 41   Character: )
ASCII code: 42   Character: *

(Note that ASCII code 32 represents the space character.)

To convert a string representation of a character into its numeric ASCII or Unicode code, use the ASC function.

Note: While ReadyBASIC supports the Unicode standard, the Courier New font presently used for the console display may not support all characters in the Unicode palette.

TODO: Insert or link to basic ASCII table. Link to Unicode charts (off-site)

Copyright 2006-2008, Kevin Matz, All Rights Reserved.