. .


ST 4U 176: Exploring Class String

January 2, 2012 12:39:42.341

Today's Smalltalk 4 You starts looking at the basic Smalltalk class libraries in VA Smalltalk, starting with String. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:


If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

Today we'll start looking at some of the base Smalltalk class libraries in VA Smalltalk, starting with class String. To get started, we want to browse the String hierarchy, in order to get a full picture of the local and inherited APIs:/p>

Browse Hierarchy

Browse Hierarchy

After selecting the launcher pulldown and entering String in the dialog, you should see this:


The second pane from the left contains a list of all the applications that define or extend class String. If you look at the status line, you'll see the defining application; you can also find that by scrolling through the list and looking for the application notated with an asterisk. You can see the methods for one application, or select all applications and see the full (at least based on what you have loaded) definition:

Select all Applications

Notice the asterisk in application CLDT, which tells us where class String is defined:


Looking at the method categories, you'll see the ANSI-API category, which contains the standard API for the class, as defined in the specification for Smalltalk. Open up a workspace, and you can try some of these messages out:

str := 'James Robertson'.
str asByteArray. 
str asSymbol. 
str at: 3. $m
str copy at: 3 put: $y.
str includes: $J. true
str replaceFrom: 1 to: 3 with: 'jam' startingAt: 1.

Try the second one; you should see this if you display the result:


Now try the #at:put: message:


one of the changes made to Smalltalk by the ANSI spec was to make Strings read-only objects - that's the exception you are seeing. To do what is being tried here, you need to make a copy first. There's a lot more to explore in Class String - just try experimenting in a Workspace.

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

[st4u176-iPhone.m4v ( Size: 7993629 )]

posted by James Robertson

 Share Tweet This