8.3: Characters
- Page ID
- 36374
Character
is defined in the Collections-Strings category as a subclass of Magnitude
. Printable characters are represented in Squeak as $⟨char⟩. For example:
$a < $b → true
Non-printing characters can be generated by various class methods. Character class»value: takes the Unicode (or ASCII) integer value as argument and returns the corresponding character. The protocol accessing untypeable characters contains a number of convenience constructor methods such as backspace
, cr
, escape
, euro
, space
, tab
, and so on.
Character space = (Character value: Character space asciiValue) → true
The printOn:
method is clever enough to know which of the three ways to generate characters offers the most appropriate representation:
Character value: 1 → Character value: 1 Character value: 32 → Character space Character value: 97 → $a
Various convenient testing methods are built in: isAlphaNumeric
, isCharacter
, isDigit
, isLowercase
, isVowel
, and so on.
To convert a Character
to the string containing just that character, send asString
. In this case asString
and printString
yield different results:
$a asString → 'a' $a → $a $a printString → '$a'
Every ascii Character
is a unique instance, stored in the class variable CharacterTable
:
(Character value: 97) == $a → true
Characters
outside the range 0 to 255 are not unique, however:
Character characterTable size → 256 (Character value: 500) == (Character value: 500) → false