Reputation: 1631
How can I convert a string (of one character) to character ?
Upvotes: 0
Views: 551
Reputation: 15560
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 :)
Upvotes: 5