Search code examples
smalltalksqueak

How can I convert a string (of one character) to character in squeak?


How can I convert a string (of one character) to character ?


Solution

  • You don't really have to convert it, but get it.

    In Smalltalk, a String is a Collection of characters.

    As for every collection, sending the first method will give you it's first component - the first Character. If you have a single-character String, that would get you that single Character.

    You can send it the at: message, too, with a given index. 'Test' at: 2 would give you the $e - Collections are 1-based, at least on the Pharo version I'm testing on :)