Skip to main content
Engineering LibreTexts

8.3: Characters

  • Page ID
    36374
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)

    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
    

    This page titled 8.3: Characters is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by Andrew P. Black, Stéphane Ducasse, Oscar Nierstrasz, Damien Pollet via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.