Strings
- Vectors containing 8-bit characters.
- String literals yield canonical strings, which are immutable. No two canonical strings have the same sequence of characters. Can use identity (==) to test equality.
- Sending copyMutable to a canonical string gives you a mutable string. Responds to at:Put: , etc.
- Useful methods in traits string.
|
Strings
Strings are vectors which can contain 8-bit characters.
There are two kinds of strings in Self, mutable strings and immutable
strings, also known as canonical strings.
A string literal, e.g., 'foo', is always a canonical string. The Virtual Machine has an
internal table of canonical strings, such that there are no two canonical strings with
the same sequence of characters. Hence, identity comparison can be used as
equality on canonical strings. Self's identity comparison message is ==,
just like Smalltalk. Canonical strings cannot be modified.
To do string processing, you can make mutable strings from canonical strings by
sending copyMutable.
Mutable strings respond to at:Put:, first:, etc.
Most of the useful operations on strings are defined in traits string. There you will
find methods to do simple parsing, evaluating strings as Self expressions,
pattern matching, ordering, and many other things.
One unusual feature (especially for Smalltalk programmers): when you send at: to
a string, the returned value is a one-element string! There are no distinct character
objects.
|