links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Last updated at 8:40 am UTC on 16 September 2017

String class comment

(Squeak 5.0)
A String is an indexed collection of Characters. Class String provides the abstract super class for ByteString (that represents an array of 8-bit Characters) and WideString (that represents an array of 32-bit characters). In the similar manner of LargeInteger and SmallInteger, those subclasses are chosen accordingly for a string; namely as long as the system can figure out so, the String is used to represent the given string.

Strings support a vast array of useful methods, which can best be learned by browsing and trying out examples as you find them in the code.

Here are a few useful methods to look at...
String match:
String contractTo:

String also inherits many useful methods from its hierarchy, such as
SequenceableCollection ,
SequenceableCollection copyReplaceAll:with:

Strings are kept as Unicode code points arrays, and converted to encoded forms when entering/exiting the system.

Pharo/Squeak Strings keep data in UTF32 encoding form, where 1 codepoint = 1 code unit, dynamically switched between Latin1 (ByteStrings) and UTF32 (WideStrings) encoding schemes as needed.

Subclasses are:

The distinction between ByteString and WideString is a mostly invisible implementation detail.

See String equivalence (Unicode)

Some common instance methods (too many to list but here are a few)

Some common class methods


 "'abcd' capitalized" -> 'Abcd'
 "'abcd' endsWithAnyOf: #('d', 'D')" -> true
 "('abcd' at:2)." -> $b
 "'abcd' at: 2 put: $3" -> $3 (returns the put: argument)
 "c _ 'abcd'. c byteAt:2 put:35. c." -> 'a#cd' 
 "('a,b c,d' findTokens: (String with: Character cr))
       collect: [:aLine | aLine findTokens: ',']

Generated documentation?

The objects of the class String are collections of characters which have specific methods for dealing with them.
(Squeak 3.3a-4664)
String selectors size is 173
String allSelectors size is 730
ProtoObject #()
Object #()
Collection #()
Text #()
ArrayedCollection #()
String #()
Symbol #()

Hints and tips

Simple string pattern matching! Do print it on each line,
see method
String>>match: for more details."
'abc*' match: 'abcdef'
'ab#de#' match: 'abcdef'
'*def' match: 'abcdef'

See also
Reading a file into a string
Some String messages of interest