Home Up Contents Search

Text - Characters

Variables of type char are designed to hold ASCII codes, that is, a number that stands for a particular textual character. Each is a byte long and represents a single printable or control character. For example:

var

C : char;
N : integer;

begin

...

C := 'A';


It can be useful to get at the underlying numeric value of a character; this operation is performed by the Ord function:

N := Ord(C);

Similarly, it is often useful to turn an ordinal value into a character; this operation is performed by the Chr function.

C := Chr(33); { C = '!' }

Arrays of characters are such useful structures that Turbo Pascal provides the string type for working with them.

program CharDemo;
var

C : char;
J : byte;

begin

J := 50; C := Chr(J); Writeln(C); J := Ord(C); Writeln(J);
C := 'A'; J := Ord(C); Writeln(J); C := Chr(2); Writeln(C);

end. { CharDemo }

 
 
Previous Next
Send mail to ljschwerin@hotmail.com with questions or comments about this web site.

Copyright © 1999-2002 Leon Schwerin
Last modified: 04 March 2002
1