| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Converts a numeric ASCII code to a character.
Chr( <nAsciiCode> ) --> cCharacter
The function returns a single character that has the numeric ASCII code <nAsciiCode>.
The function converts a numeric value to a character of the corresponding ASCII code. ASCII codes are integer values in the range of 0 to 255. When a value outside this range is passed, it is corrected according to the following rules:
| 1) | If the value <nAsciiCode> is larger than 255, the ASCII code is calculated as <nAsciiCode> modulus 256. |
| 2) | If <nAsciiCode> is negative, the ASCII code is calculated as 256 + <nAsciiCode> modulus 256. |
The Chr() function is used to compose character strings consisting of non-printable characters. Such strings can contain control characters for a device, like printer or keyboard, for example.
| See also: | Asc(), Inkey(), KEYBOARD |
| Category: | Numeric functions , Conversion functions |
| Source: | rtl\chrasc.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example converts various numeric values to characters
// and creates a text string including non-printable characters
PROCEDURE Main
LOCAL cText
? Chr(65) // result: A
? Chr(322) // result: B
? Asc( Chr(322) ) // result: 66
? 322 % 256 // result: 66
n := -142
? Chr( n ) // result: r
? Asc( Chr(n) ) // result: 114
? 256+n % 256 // result: 114
cText := "This is a"
cText += Chr(13) + Chr(10)
cText += "two line text"
? cText
RETURN
http://www.xHarbour.com