Squeak
  links to this page:    
View this PageEdit this PageUploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
String
Last updated at 4:36 pm UTC on 16 January 2006

String class comment

String supports 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: (search and replace)

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


Some common class methods


Examples

"'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'



(from: email by Göran Hultgren)
Newbie tip: Reading in a file in a String. (The path should be expressed as expected on your OS.)
  | myString |
  myString := (FileStream readOnlyFileNamed: 'd:\file.txt')
                    contentsOfEntireFile