SYNTAX: Chr(Number: integer): char;
Ord(Character: char): integer;
DESCRIPTION:
The Chr function returns the alphabet Character equal to the ordinal value of the Number parameter.
The Ord function returns the ordinal value (number) of the Character parameter.
NOTE: Individual text and alphabet characters have an ordinal value. These values are used by computers to represent the characters numerically in bytes. For example, the ordinal values of the Capital letters A through Z are 65 through 90. Example, Ord('A') equals 65. Ord('B') equals 66, and so forth… Chr(65) equals 'A', Chr(90) equals 'Z'. Using these two functions allows you to determine the ordinal value of any Character, or to determine the Character that represents an ordinal number.
PARAMETERS:
Number: Number is a decimal value from 0 through 255. This value (ordinal value) represents a character to the computer. The values from 0-31 are Control characters (like the ESC key = 27). The values from 32-64 represent the space character=32, plus numbers (0-9) and other misc. characters. The values from 65-90 are the capitalized alphabet letters (A-Z). The values from 91-96 are various punctuation characters. The values from 97-122 are the small alphabet letters (a-z). The values from 123-255 are various punctuation characters and draw characters.
Character: Character can be any alphabet letter (either capitalized or not), plus all the other characters generally available on a computer keyboard.
EXAMPLE: The following example counts from 65 to 90 and prints the alphabet Character represented by the count value. The small alphabet Characters are also printed by adding 32 to the value of Count (resulting in 97-122).
Lastly, a loop examines each character in the word 'HELLO' and prints the ordinal value of the character.
var {Start of Variable Declarations}
Count: integer; {Declare Count as an integer}
begin {Start of Main programming code}
for Count:=65 to 90 do writeln(Chr(Count),' ',Chr(Count + 32)); {Print Characters}
for Count:=1 to 5 do writeln(Ord(Copy('HELLO',Count,1))); {Print Ordinals}
end; {End of program}