Functions and Directives

Function Chr() Foundation

Converts a numeric ASCII code to a character.

Chr( <nAsciiCode> ) --> cCharacter
<nAsciiCode> is an integer numeric value in the range of 0 to 255.

Chr() converts <nAsciiCode> to the corresponding ASCII character. If a numeric value outside the valid range for ASCII characters is passed, it is implicitly adjusted by a modulus 256 operation (Chr(257)==Chr(1) --> .T.).


Chr() is a conversion function which translates a numeric value into the equivalent ASCII character. The counterpart function Asc() reverses the function Chr(). Chr() can be used in many places:

With Inkey() to convert return values into characters

When sending characters into the keyboard buffer

To produce a warning tone (Chr(7))

When sending characters to the printer

The character Chr(0) has a length of 1 and is handled like any other character and can be sent to any device or file.


// The example shows various results of the function Chr() 


   ? Chr(65)                    // result: A 
   ? Chr( Asc("A") + 32 )       // result: a 
   ? Chr(7)                     // result: warning tone 
   ? Chr(10)                    // result: new line 

                                // length of a null string 
   ? Len("")                    // result: 0 

                                // length of the null character 
   ? Len(Chr(0))                // result: 1 


If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.