Skip to main content
Engineering LibreTexts

10.3: Characters

  • Page ID
    39628
    \( \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}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Character is defined a subclass of Magnitude. Printable characters are represented in Pharo 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 home
    
    Character value: 2
    >>> Character value: 2
    
    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'
    

    Like SmallInteger, a Character is a immediate value not a object reference. Most of the time you won’t see any difference and can use objects of class Character like any other too. But this means, equal value characters are always identical:

    (Character value: 97) == $a
    >>> true
    

    This page titled 10.3: Characters is shared under a CC BY-SA 3.0 license and was authored, remixed, and/or curated by via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.