Testing whether an object is string-like.

Problem

You have to test if an object is a string, or string-like.

Solution

Use the built in method isString. Evaluate the following lines in Dolphin Smalltalk to see how it works.

'Hello World!' isString.
$A isString.

This also works for user defined sub-classes of String, as demonstrated in the next code segment which should be evaluated in Dolphin Smalltalk.

| aString |

aString := MyString new.
aString isString

Technorati tags: