Chr$ ( ascii )
Parameters
| ascii - the character code to convert |
Description
|
Returns a one-character string with the given character code. Chr( 65 ) is "A". It is the inverse of Asc. Chr is how you get at characters you cannot type into a string literal. Chr( 34 ) gives you a double quote, Chr( 9 ) a tab, and Chr( 13 )+Chr( 10 ) a Windows line break for writing to a file. It also builds characters that live beyond the letters and digits in your font sheet - box-drawing pieces, arrows, or a degrees sign. The other everyday use is arithmetic on letters: Chr( Asc( "A" )+n ) walks through the alphabet, which is handy for labelling save slots, generating level codes, or stepping a cipher. Only the low eight bits of the value are used, so codes wrap round outside 0 to 255 rather than producing a multi-byte character. See also: Asc, String, Mid, Str. |
Example
; Chr Example ; ----------- ; Chr$ converts an ASCII code back into a one-character string. ; It is the reverse of Asc. Print "Chr$(65) = "+Chr$(65)+" (65 is the code for A)" Print "" ; Build the letter row for a high-score name-entry screen alphabet$="" For code=65 To 90 alphabet$=alphabet$+Chr$(code) Next Print "Name-entry letters: "+alphabet$ ; Chr$(34) is the double-quote - the only way to put one in a string Print "" Print "The pilot said "+Chr$(34)+"Fire!"+Chr$(34) ; Round trip: Asc undoes Chr$ Print "" Print "Chr$(90) = "+Chr$(90)+" and Asc('Z') = "+Asc("Z") Print "" Print "Press any key to close the example" WaitKey End
Index