Cuis-What Strings are made of and how

From Cuis CookBook
Revision as of 22:21, 4 May 2025 by Nmingott (talk | contribs)
Jump to navigation Jump to search
  • 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] "