CHR
s = CHR (x)
Returns an one-char string of character with ASCII code
x
.
See ASC to convert a character to ASCII code.
Example 1
print "ASCII code 65 is '" + chr(65) + "'" ' Output ASCII code 65 is 'A'
Example 2: Get escape character
The CHR command is useful for obtaining and printing the escape character (ASCII 27). For more information about escape codes see article “Escape Codes”
PRINT CHR(27) + "[1mTHIS IS BOLD" + CHR(27) + "[0m"
PRINT CHR(27) + "[3mThis is italic" + CHR(27) + "[0m"
PRINT CHR(27) + "[4mThis is underline"
Example 3: Print ASCII table
REM display the ASCII and the extended tables
For n = 0 To 255
If n = 0 Then
Color 15, 0: Locate 1, 1
Print "Standard 7-bit ASCII table (character codes 0 - 127):";
Elseif n = 128 Then
print
print
Input "Press return to see nonstandard table", k
Color 15, 0: Cls: Locate 1, 1
Print "Nonstandard 8-bit Extended table (character codes 128 - 255):";
Endif
If n <= 31 Then ' control characters (e.g. new-line, tab, etc).
Read c
Elseif n = 32 Then ' regular space (invisible...)
"sp"
c = Elseif n = 127 Then ' lonesome control character "del"
"del"
c = Else
Chr(n) ' ASCII code --> character
c = Endif
Locate (n Mod 16) + 3, (((n \ 16) Mod 8) * 9) + 1
Color 7: Print Using "000 "; n; ' ASCII code
Color 14: Print c; ' ASCII (or ANSI) character
Next
Color 7, 0: Print: Print
Print " * Nonstandard characters might look different on another system."
End
' nonprintable control characters (ASCII codes 0..31):
Data "nul", "soh", "stx", "etx", "eot" ' 0..4
Data "enq", "ack", "bel", "bs" , "tab" ' 5..9
Data "lf" , "vt" , "np" , "cr" , "so" ' 10..14
Data "si" , "dle", "dc1", "dc2", "dc3" ' 15..19
Data "dc4", "nak", "syn", "etb", "can" ' 20..24
Data "em" , "eof", "esc", "fs" , "gs" ' 25..29
Data "rs" , "us" ' 30..31
Code samples using CHR
003 conditional branching.bas
004 loops.bas
005 challenge.bas
100lines.bas
2048.bas
2048.bas
7gables.bas
autumn scene.bas
B+B.bas
base64.bas
bb2fork smurf.bas
blackbox.bas
Blackbox.bas
calc.bas
character map.bas
Charmap.bas
demanda.bas
dmsareaplot.bas
dmsareareadmd.bas
dogstar5.bas
Easter_Butcher.bas
Easter_Carter.bas
Easter_Oudin.bas
eliza.bas
esoteric.bas
Euro_calculator.bas
ezinvaders.bas
factor.bas
Factor.bas
String
ASC
BCS
BIN
CBS
CHOP
CHR
DISCLOSE
ENCLOSE
FORMAT
HEX
INSTR
JOIN
LCASE
LEFT
LEFTOF
LEFTOFLAST
LOWER
LTRIM
MID
OCT
REPLACE
RIGHT
RIGHTOF
RIGHTOFLAST
RINSTR
RTRIM
SINPUT
SPACE
SPC
SPLIT
SPRINT
SQUEEZE
STR
STRING
TRANSLATE
TRIM
UCASE
UPPER
VAL
If there is insufficient information on this page and you wish learn more about CHR,
please send an email to smallbasic@gmail.com. You can help to improve information about
CHR by submitting a pull request,
click View Source for details. Note, an offline language reference text file is also available - see the Download section.