Skip to content

What Strings are made of and how

Dr. Nicola Mingotti edited this page Dec 11, 2021 · 1 revision
  • Strings Smalltalk and many other languages are a sequence of Characters.

  • A Character is typed in like this:

$a class .    "=> Character "
$b class.     "=> Character "
  • Therefore you can make a string converting strictly from a sequence of Characters as in
#($h $e $l $l $o) as: String .      "=> 'hello' "

or also

String newFrom: #($a $b $c). " 'abc' "
  • The most common way to type in a String literal is this one
s1 _ 'hello world'. 
s1 class. " String "
  • You can the convert from a String to an sequence of charaters as
s1 asArray .       "=> #($h $e $l $l $o $  $w $o $r $l $d) "
  • By default String in CuisSmalltalk as sequence of Latin1 characters, each of them is encoded in 1 byte. You can see the raw byte representation of the Characters in a string as
s1 asByteArray . "=>  #[104 101 108 108 111 32 119 111 114 108 100] "
Clone this wiki locally